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.py58 chars4 lines
Output:
main.py3 chars2 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