What is abs in Python

0 votes
I am new to Python. What is the use of abs in Python?
Jul 16, 2019 in Python by Neel
• 3,020 points
849 views

1 answer to this question.

0 votes

The abs() method returns the absolute value of the given number. If the number is a complex number, abs() returns its magnitude.

The abs() method takes a single argument:

  • num - number whose absolute value is to be returned. The number can be:
    1. integer
    2. floating number
    3. complex number

The abs() method returns the absolute value of the given number.

  • For integers - integer absolute value is returned
  • For floating numbers - floating absolute value is returned
  • For complex numbers - magnitude of the number is returned
Example - 
# random integer
integer = -20
print('Absolute value of -20 is:', abs(integer))

#random floating number
floating = -30.33
print('Absolute value of -30.33 is:', abs(floating))

Output- 

Absolute value of -20 is: 20
Absolute value of -30.33 is: 30.33
answered Jul 16, 2019 by Arvind
• 3,050 points

Related Questions In Python

+2 votes
3 answers

what is the practical use of polymorphism in Python?

Polymorphism is the ability to present the ...READ MORE

answered Mar 31, 2018 in Python by anto.trigg4
• 3,440 points
4,885 views
+4 votes
7 answers
+1 vote
7 answers
0 votes
1 answer

What is the use of raw_input function in Python?

raw_input fuction is no longer available in ...READ MORE

answered May 2, 2018 in Python by aayushi
• 750 points
1,261 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,440 views
0 votes
1 answer
0 votes
1 answer

What is the difference between str() and repr() functions in Python?

str() is mostly used to create output ...READ MORE

answered Jul 8, 2019 in Python by Arvind
• 3,050 points
1,618 views
0 votes
1 answer

What is the difference between print and pprint in Python?

As per the documentation,  The pprint module provides a capability ...READ MORE

answered Jul 8, 2019 in Python by Arvind
• 3,050 points
6,878 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP