Home >Backend Development >Python Tutorial >How to express absolute value in python

How to express absolute value in python

coldplay.xixi
coldplay.xixiOriginal
2021-03-02 16:07:0933700browse

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)] .

How to express absolute value in python

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn