Python Standard Library

Built-In Functions

abs(x)

Return the absolute value of a number. The argument may be an integer or a floating point number. If the argument is a complex number, its magnitude is returned.

print(abs(1))
print(abs(-1))
print(abs(1.0))
print(abs(-1.0))

print(abs(2+3j))

Turns out you can use j after a number in Python to denote a complex number. Didn't know that before today!

all(iterable)

Return True if all elements of the iterable are true (or if the iterable is empty).

print(all([True, True, True]))
print(all([False, False, False]))
print(all([]))
print(all([True, True, False]))
print(all([1, 1, 1]))
print(all([1, 1, None]))
print(all([None, None, None]))
print(all([]) == bool([]))

I find it a little weird that all([]) evaluates to True, since [] is falsey.

any(iterable)

Return True if any element of the iterable is true. If the iterable is empty, return False.

print(any([True]))
print(any([True, False]))
print(any([1, 0]))
print(any([True, lambda x: false]))
print(any([False, False]))
print(any([]))
Last Updated: 7/9/2020, 6:53:53 PM