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

Python abs() function

Python abs() function

Python Numbers Python 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).


Example

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

#!/usr/bin/python

print

"

abs(-45) :

"

,

abs

(

45

)

print

"

abs(100.12) :

"

,

abs

(

100.12

)

print

"

abs(119L) :

"

,

abs

(

119L

)

Running the example above produces:



abs(-45) :  45

abs(100.12) :  100.12

abs(119L) :  119

Python Numbers Python Numbers