
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
abs() in Python
The abs() function in python represents the absolute value of a numeric input. The absolute value is concerned with the value or magnitude of a number instead of the sign attached to the number. It is even more useful for complex numbers where the calculation of magnitude involves many steps.
The syntax of the function is −
abs(num)
where num can be integer,floating number or a complex number.
Example
In the below example we take all the above types of numbers and calculate their magnitude.
n = -112 print('Absolute value of a integer', abs(n)) f = -39.222 print('Absolute value of a float: ', abs(f)) c = (11 - 21j) print('Absolute value or Magnitude of a complex number:', abs(c))
Output
Running the above code gives us the following result:
('Absolute value of a integer', 112) ('Absolute value of a float: ', 39.222) ('Absolute value or Magnitude of a complex number:', 23.706539182259394)
- Related Questions & Answers
- Python - fabs() vs abs()
- abs() function in PHP
- PHP abs() Function
- What is difference in abs() and fabs() in Python?
- Duration abs() method in Java
- abs(), labs(), llabs() functions in C/C++
- abs() function for complex number in c++ ?
- The abs(), labs(), llabs() functions in C/C++
- What is the use of abs() methods in pandas series?
- What are the six foods that can be consumed while aiming for six-pack abs?
- Find Maximum value of abs(i – j) * min(arr[i], arr[j]) in an array arr[] in C++
- ChainMap in Python
- Namedtuple in Python
- Deque in Python
- OrderedDict in Python
Advertisements