Python - Numeric Functions

Numeric Functions


To find the maximum or minimum of some numbers or a list, you can use max or min.
To find the distance of a number from zero (its absolute value), use abs.
To round a number to a certain number of decimal places, use round.
To find the total of a list, use sum.
Some examples:
print(min(1, 2, 3, 4, 0, 2, 1))
print(max([1, 4, 9, 2, 5, 6, 8]))
print(abs(-99))
print(abs(42))
print(sum([1, 2, 3, 4, 5]))
Result:>>>
0
9
99
42
15
>>>




Comments

Popular posts from this blog

Python - Argument Passing

Python - How to Escape special characters in String