Home>Article>Backend Development> How to calculate absolute value in python

How to calculate absolute value in python

藏色散人
藏色散人 Original
2020-11-06 14:13:38 28252browse

In Python, the absolute value of a number can be calculated through the abs function. The syntax for using the abs function is "abs(x)", where the parameter x represents a numerical expression, and the function can return the absolute value of x.

How to calculate absolute value in python

Recommended: "python video tutorial"

Python abs() function

Description

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 (number).

Example

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 result after running the above example is:

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

The above is the detailed content of How to calculate 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