Python abs() function

Python 数字Python Numbers


Description

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


Syntax

The following is the syntax of the abs() method:

abs( x )

Parameters

  • x -- numeric expression.

Return Value

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

Examples

The following shows an example 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)

The output of the above example is:

abs(-45) :  45
abs(100.12) :  100.12
abs(119L) :  119

Python 数字Python Numbers

Other Extensions