why do we use operator abs

0 votes
In operators module we have a helper method operator.abs. But in python abs is already a function, and the only way I know to invoke the __abs__ method on an object is by function call anyway.

Is there some other fancy way I don't know about to take the absolute value of a number? If not, why does operator.abs exist in the first place, and what is an example where you would have to use it instead of plain old abs?
Apr 2, 2019 in Python by ana1504.k
• 7,910 points
724 views

2 answers to this question.

0 votes
abs(...)
    abs(a) -- Same as abs(a).

No, I don’t think there’s some other fancy way you don’t know about, or really any reason at all for this to be here at all except for consistency.
answered Apr 2, 2019 by SDeb
• 13,300 points
0 votes

 python and abs() in Python

The abs() take one argument and give absolute value. The argument can be an integer, a floating point number or a complex number.

  • If  argument is an integer or floating number, abs() returns the absolute value in integer or float.

  • if argument is  complex number abs() returns only the magnitude part and that can also be a floating point number

example

x = abs(-7.25)

output:7.25

answered Apr 3, 2019 by anonymous

Related Questions In Python

0 votes
2 answers

Why do we use return statement in python?

def maximum(x, y):     if x > y:     ...READ MORE

answered Apr 4, 2019 in Python by anonymous
1,700 views
0 votes
0 answers

how do i use the XOR operator in python regular expression?

can u give an example? READ MORE

Mar 26, 2019 in Python by Waseem
• 4,540 points
1,395 views
0 votes
1 answer

Why do we not follow the "off by one" rule in python

It's because of the way in which ...READ MORE

answered Nov 15, 2020 in Python by Gitika
• 65,910 points
474 views
0 votes
1 answer

Why there is no do while loop in python

There is no do...while loop because there ...READ MORE

answered Aug 6, 2018 in Python by Priyaj
• 58,090 points
7,011 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,023 views
0 votes
1 answer
0 votes
1 answer

Why do variables have bigger scopes in Python than in C?

Only functions, modules, and the bodies of ...READ MORE

answered Jul 2, 2019 in Python by SDeb
• 13,300 points
765 views
0 votes
1 answer

What are the ternary conditional operator in Python?

The Ternary Conditional operator was added in ...READ MORE

answered Sep 19, 2018 in Python by SDeb
• 13,300 points
543 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