Function Details: abs

Description


Returns the absolute value of a number.


Extended Description


The abs() function returns the absolute value of a number. The argument may be an integer, a floating point number, or an object implementing __abs__(). If the argument is a complex number, its magnitude is returned.


Exceptions


  • TypeError: If the argument is not a number and doesn't implement __abs__()

Read More about abs from Python Documentation

Function Signature


abs(x: Number) -> Number

Module: builtins

Parameters


This function takes one parameter: x (a number). It can be an integer, float, or complex number.


Parameter List


  • x: Number

Return


Returns the absolute value of the argument. The return type depends on the input type: int for integers, float for floats, and float for complex numbers.


Return Type


Number

Output

Explanation

This example demonstrates abs() with different number types: integers, positive and negative floats, and a complex number.