The unofficial CircuitPython Reference

abs()

description

Absolute is a built-in function that takes one numeric argument and returns the absolute value of the argument. The absolute value is always positive and reflects the magnitude of the value independent of its sign.

syntax

abs(number)

methods

parameters

number : a float or int value

(number can be a variable. The contents of the variable must be float or int)

returns

Returns absolute value of the parameter which is always a positive number.

number: if number is greater than or equal to 0.

-number: if number is less than 0.

example code

serial output:

Absolute value of -5 is: 5

Absolute value of -1.45 is: 1.45

see also:

No items found.