Python abs() function


(Sponsors) Get started learning Python with DataCamp's free Intro to Python tutorial. Learn Data Science by completing interactive coding challenges and watching videos by expert instructors. Start Now!


The abs() function returns the absolute value (just magnitude without sign) of the number.

Its syntax is as follows:

ParameterDescription
xAny numeric value

Here is an example:

The result is quite obvious for integers and floats. In case of a complex number
z = x + yi the abs() function calculates the absolute value as follows:

Absolute value = |z| = √x² + y²

 


Other Tutorials (Sponsors)

This site generously supported by DataCamp. DataCamp offers online interactive Python Tutorials for Data Science. Join over a million other learners and get started learning Python for data science today!


Leave a Reply

Your email address will not be published. Required fields are marked *