On this page
abs
Prev: True | Up: __builtins__ | Next: aiter
Rel: divmod, max, min, pow, round
Ref: docs.python.org — abs
Tags: #public #python3 #builtins
Import & Availability
# Built-in (available globally without import)
from builtins import abs
Overview & Signature
abs(x, /)
Return the absolute value of the argument.
Usage
assert abs(-42) == 42
assert abs(-3.5) == 3.5
assert abs(3 + 4j) == 5.0 # Euclidean magnitude for complex numbers
Gotchas
- Preserves
intfor integers (unlikemath.fabs(), which always returnsfloat). - Customizable via
__abs__()on your own numeric classes.
REPL Inspect
help(abs)
Linked from
- tuts/python3/__builtins__
- tuts/python3/__builtins__/__builtins__
- tuts/python3/__builtins__/aiter
- tuts/python3/__builtins__/divmod
- tuts/python3/__builtins__/max
- tuts/python3/__builtins__/min
- tuts/python3/__builtins__/pow
- tuts/python3/__builtins__/round
- tuts/python3/__builtins__/sum
- tuts/python3/__builtins__/True
Related notes
- tuts/python3/__builtins__/__builtins__ Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/aiter Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/divmod Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/max Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/min Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/pow Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/round Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/True Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__ links to this page; shared tags: #builtins
- tuts/python3/__builtins__/sum links to this page; shared tags: #builtins