Python Get the Absolute Value of a Number
In Python, getting the absolute value of a number is very simple; you can use the built-inabs()function. This function takes a number as an argument and returns its absolute value.
Example
number = -10
absolute_value = abs(number)
print(absolute_value)
absolute_value = abs(number)
print(absolute_value)
Code Explanation:
number = -10: define a variablenumber, and assign it the value-10。absolute_value = abs(number): useabs()function to getnumberthe absolute value, and assign the result to the variableabsolute_value。print(absolute_value): printabsolute_valuethe value of
Output result:
10Other Extensions
Python3 Examples