Absolute Value Python

absolute-value-python

Python abs()

Python abs() is an implicit capacity accessible with the standard library of python. It restores the total an incentive for the given number. Supreme estimation of a number is the incentive without thinking about its sign. The number can be whole number, coasting point number or complex number. On the off chance that the given number is perplexing, at that point it will restore its size.

Syntax:

abs(value)

Parameters: (value)

The input value to be given to abs() to get the absolute value. It can be an integer, a float, or a complex number.

Return Value:

It will return the absolute value for the given number.

  • In the event that the information is a whole number, the return esteem additionally will be a number.
  • On the off chance that the information is a buoy, the return worth will likewise be coast.
  • On the off chance that the info is a mind boggling number, the return worth will be the size of the information.

Examples:

Code Example 1: Integer and Float number

To get the absolute value of an integer and float number check this code:

# testing abs() for an integer and float

int_num = -25

float_num = -10.50

print("The absolute value of an integer number is:", abs(int_num))
print("The absolute value of a float number is:", abs(float_num))

Output:

The absolute value of an integer number is: 25
The absolute value of a float number is: 10.5

Example 2: Complex Number

To get absolute value of complex number

# testing abs() for a complex number

complex_num = (3+10j)

print("The magnitude of the complex number is:", abs(complex_num))

Output:

The magnitude of the complex number is: 10.44030650891055

Summary:

  • Abs() is an underlying capacity accessible with python, and it will restore you the total an incentive for the info given.
  • Worth is an information incentive to be given to abs() to get the supreme worth. It tends to be a number, a buoy, or an unpredictable number.
  • The abs() technique takes one contention, for example the worth you need to get the total.
  • The abs work restores the supreme incentive for the given number.