Home > Article > Backend Development > How to express absolute value in python
The expression method of absolute value in python: [abs()] function is used to obtain the absolute value of a number. The parameters can be negative numbers, positive numbers, floating point numbers or long integers. The syntax is [abs(x)] .
The operating environment of this tutorial: Windows 7 system, python version 3.9, DELL G3 computer.
Absolute value representation in python:
python abs()
The function is used to obtain the absolute value of a number. The parameter can be a negative number, Positive number, floating point number or long integer.
Syntax:
abs( x )
The following are the detailed parameters:
X: This is a numerical expression.
Return value: The absolute value of x.
For example:
#!/usr/bin/python print "abs(-45) : ", abs(-45) print "abs(100.12) : ", abs(100.12) print "abs(119L) : ", abs(119L)
Running result:
abs(-45) : 45 abs(100.12) : 100.12 abs(119L) : 119
Related free learning recommendations: python video tutorial
The above is the detailed content of How to express absolute value in python. For more information, please follow other related articles on the PHP Chinese website!