I noticed that in python there are two similar looking methods for finding the absolute value of a number:
First
abs(-5)
Second
import math
math.fabs(-5)
How do these methods differ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
math.fabs()converts its argument to float if it can (if it can’t, it throws an exception). It then takes the absolute value, and returns the result as a float.In addition to floats,
abs()also works with integers and complex numbers. Its return type depends on the type of its argument.