take the absolute value of a number in python

To take the absolute value of a number in Python, you can use the built-in abs() function. The abs() function returns the absolute value of the given number. Here is an example:

main.py
num = -10
absolute_value = abs(num)
print(absolute_value)
58 chars
4 lines

Output:

main.py
10
3 chars
2 lines

In this example, we assigned the value -10 to the variable num. We then passed num to the abs() function, which returned the absolute value of -10, 10. We then printed the resulting absolute value to the console.

gistlibby LogSnag