Python Abs

Python Abs (or absolute number) will return the absolute distance a number is away from 0. This simply means, how far away is it from 0?

For example if you were to take a look at a number line, the number 4 is 4 spots away from 0. The number -3 (on the left of the number line) is 3 spots away from zero. 4 and 3 in this case are the absolute values.

Sometimes this is referred to at the “magnitude” of your number.

This is an extremely common statical function that you’ll see throughout the rest of your life.

Let’s take a look at a python abs code sample


In [1]:
# Define a list of variables
x = 3
y = -6
In [3]:
# Take the absolute of the numbers
print ("The absolute number of 'x' is {}".format(abs(x)))
print ("The absolute number of 'y' is {}".format(abs(y)))
The absolute number of 'x' is 3
The absolute number of 'y' is 6

Link to code above

Check out more Python Vocabulary on our Glossary Page