The abs() function is used to return the absolute value of a number.
Syntax:
abs(number) number : Can be integer, a floating point number or a complex number
The abs() takes only one argument, a number whose absolute value is to be returned. The argument can be an integer, a floating point number or a complex number.
- If the argument is an integer or floating point number, abs() returns the absolute value in integer or float.
- In case of complex number, abs() returns only the magnitude part and that can also be a floating point number.
# Python code to illustrate # abs() built-in function # floating point number float = -54.26print('Absolute value of float is:', abs(float)) # An integer int = -94print('Absolute value of integer is:', abs(int)) # A complex number complex = (3 - 4j) print('Absolute value or Magnitude of complex is:', abs(complex)) |
Output:
Absolute value of float is: 54.26 Absolute value of integer is: 94 Absolute value or Magnitude of complex is: 5.0
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- Python | fabs() vs abs()
- Python | Pandas Series.abs()
- Python | Pandas DataFrame.abs()
- Python | Tensorflow abs() method
- Python | Pandas Panel.abs()
- Python - PyTorch abs() method
- Important differences between Python 2.x and Python 3.x with examples
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Sort Python Dictionaries by Key or Value
- Python | Merge Python key values to list
- Reading Python File-Like Objects from C | Python
- Python | Add Logging to a Python Script
- Python | Add Logging to Python Libraries
- JavaScript vs Python : Can Python Overtop JavaScript by 2020?
- Python | Visualizing O(n) using Python
- Python | Index of Non-Zero elements in Python list
- Python | Convert list to Python array
- MySQL-Connector-Python module in Python
- Python - Read blob object in python using wand library
- Python | PRAW - Python Reddit API Wrapper
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : AdityaPandey1

