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

Python3 abs() Function

Python3 abs() Function

Python3 Numbers Python3 Numbers


Description

The abs() function returns the absolute value of a number.


Syntax

The syntax of the abs() method is as follows:


abs( x )

Parameters


Return Value

The function returns the absolute value of x (a number); if the argument is a complex number, it returns its magnitude.


Example

The following shows examples of using the abs() method:

Example

#!/usr/bin/python3

print

(

"abs(-40) : "

,

abs

(

40

)

)

print

(

"abs(100.10) : "

,

abs

(

100.10

)

)

Running the example above produces:


abs(-40) :  40
abs(100.10) :  100.1

Related articles:Difference between Python fabs() and abs()

Python3 Numbers Python3 Numbers