Absolute Value in Python

Level 115 keystrokes

This prints the absolute value of -42, which is 42. The abs() function removes the negative sign.

Python code

# abs() returns the absolute value: the distance from zero, never negative
# abs(-42) drops the minus sign and returns 42, which is printed
1print(abs(-42))

Output

42
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Python code and how often they appear.

  • (× 2
  • )× 2
  • -× 1

More Python examples at level 1

← Python typing practice