How to express absolute value in python

coldplay.xixi
Release: 2023-01-03 09:26:59
Original
33679 people have browsed it

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 )
Copy after login

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)
Copy after login

Running result:

abs(-45) :  45
abs(100.12) :  100.12
abs(119L) :  119
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template