Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Get the Absolute Value of a Number

Python Get the Absolute Value of a Number

Document Object Reference Manual Python3 Examples

In Python, getting the absolute value of a number is very simple: you can use the built-in abs() function. This function takes a number as its argument and returns its absolute value.

Example

number

=

10

absolute_value

=

abs

(

number

)

print

(

absolute_value

)

Code analysis:

Output result:

10

Document Object Reference Manual Python3 Examples