Python 3 - Number abs() Method


Advertisements

Description

The abs() method returns the absolute value of x i.e. the positive distance between x and zero.

Syntax

Following is the syntax for abs() method −

abs( x )

Parameters

x − This is a numeric expression.

Return Value

This method returns the absolute value of x.

Example

The following example shows the usage of the abs() method.

#!/usr/bin/python3

print ("abs(-45) : ", abs(-45))
print ("abs(100.12) : ", abs(100.12))

Output

When we run the above program, it produces the following result −

abs(-45) :  45
abs(100.12) :  100.12
python_numbers.htm
Advertisements