How / why we use operator.abs

The operators module has a helper method operator.abs . But in python abs there is already a function, and the only way I know to use the __abs__ method for an object is to call the function.

Is there any other bizarre way that I don't know to accept the absolute value of a number? If not, why does operator.abs exist in the first place, and what is an example where you have to use it instead of the plain old abs ?

+4
source share
1 answer

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

No, I don’t think that this is any other way that you don’t know about, or about any reason whatsoever, for it to be here at all, except for the sequence (since operator has methods for other __operator__ s )

+1
source

Source: https://habr.com/ru/post/987816/


All Articles