Skip to content

Common Functions

Python offers a set of built-in functions that perform frequent operations such as counting, aggregation, sorting, and calculating minimum or maximum values. These functions are widely used in daily programming due to their simplicity and efficiency, and are part of the core of the language, so they do not require additional import.

FunctionDescription
len() Returns the number of items in a sequence or iterable object.
sum()Returns the sum of all numeric elements of a sequence.
max()Returns the maximum value of a sequence.
min()Returns the minimum value.
sorted()Returns a new sorted list.
abs()Returns the absolute value of a number.
round()Rounds a decimal number to the nearest integer (or to a certain precision).
pow()Raises a number to a power (equivalent to **).
divmod()Returns a tuple with the quotient and remainder of a division.
enumerate()Returns an enumerated object (index and value) over an iterable.

Below I will explain in more detail how these functions work:

Typical use: To count the number of elements in a sequence or collection.

len.py
names = ['Ana', 'Luis', 'Pedro']
print(len(names))

Output:

type.py
3

Typical use: To calculate the total sum of the numeric elements of a sequence.

sum.py
numbers = [10, 20, 30]
print(sum(numbers))

Output:

sum.py
60

Typical use: To get the highest value of a sequence.

max.py
ages = [15, 42, 37, 29]
print(max(ages))

Output:

max.py
42

Typical use: To get the lowest value of a sequence.

min.py
temperatures = [23, 18, 30, 21]
print(min(temperatures))

Output:

min.py
18

Typical use: To sort the elements of a sequence and return a new sorted list.

sorted.py
letters = ['d', 'a', 'c', 'b']
print(sorted(letters))

Output:

sorted.py
['a', 'b', 'c', 'd']

Typical use: To get the absolute value of a number.

abs.py
number = -15
print(abs(number))

Output:

abs.py
15

Typical use: To round a decimal number to the nearest integer.

round.py
pi = 3.14159
print(round(pi, 2))

Output:

round.py
3.14

Typical use: To raise a base number to a power.

pow.py
print(pow(2, 3)) # 2^3

Output:

pow.py
8

Typical use: To get the quotient and remainder of a division.

divmod.py
resultado = divmod(10, 3)
print(resultado)

Output:

divmod.py
(3, 1)

Typical use: Typical use: To iterate over a sequence obtaining index and value.

enumerate.py
fruits = ['apple', 'banana', 'cherry']
for index, value in enumerate(fruits):
print(index, value)

Output:

enumerate.py
0 manzana
1 banana
2 cereza