18 Essential Python Built‑in Functions Every Beginner Should Master
This tutorial introduces 18 core Python built‑in functions, explains their typical use cases, and provides clear code examples so beginners can write more efficient, concise, and readable programs while laying a solid foundation in Python fundamentals.
Overview of Python built‑in functions
Python includes a collection of built‑in functions that can be used without importing any module. They simplify common programming tasks such as input/output, type conversion, sequence manipulation, numeric calculations, and functional‑style processing.
print()
Outputs a string representation of the given objects to the standard output.
print("Hello, World!") # prints Hello, World!len()
Returns the number of items in a container (e.g., list, tuple, string, dict).
my_list = [1, 2, 3]
print(len(my_list)) # prints 3input()
Reads a line of text from the user (the trailing newline is stripped).
name = input("Enter your name: ")
print(f"Hello, {name}!") # prints a greetingint(), float(), str()
Convert a value to an integer, floating‑point number, or string respectively.
age = int(input("Enter your age: "))
print(f"Your age is {age}") # prints the age as an integerlist(), tuple(), dict()
Create mutable lists, immutable tuples, or mapping dictionaries.
# list from an iterable
numbers = list(range(1, 6))
print(numbers) # [1, 2, 3, 4, 5]
# tuple from an iterable (note the single argument)
points = tuple([(1, 2), (3, 4)])
print(points) # ((1, 2), (3, 4))
# dictionary with keyword arguments
mapping = dict(one=1, two=2, three=3)
print(mapping) # {'one': 1, 'two': 2, 'three': 3}range()
Generates an immutable sequence of integers. It accepts start, stop, and optional step arguments.
for i in range(1, 6):
print(i) # 1 2 3 4 5
# with a step argument
for i in range(0, 10, 2):
print(i) # 0 2 4 6 8sum()
Returns the arithmetic sum of all elements in an iterable. An optional start value can be provided.
numbers = [1, 2, 3, 4, 5]
print(sum(numbers)) # 15
print(sum(numbers, 10)) # 25 (adds 10 as the initial value)max(), min()
Return the largest or smallest item in an iterable, or the largest/smallest of two or more arguments.
numbers = [1, 2, 3, 4, 5]
print(max(numbers)) # 5
print(min(numbers)) # 1
# with multiple arguments
print(max(3, 7, 2)) # 7
print(min('a', 'c', 'b')) # asorted()
Creates a new list containing all items from the iterable in sorted order. Optional key and reverse parameters control the sorting criteria.
numbers = [3, 1, 4, 1, 5, 9]
sorted_numbers = sorted(numbers)
print(sorted_numbers) # [1, 1, 3, 4, 5, 9]
# sort strings by length, descending
words = ["apple", "fig", "banana"]
print(sorted(words, key=len, reverse=True)) # ['banana', 'apple', 'fig']reversed()
Returns an iterator that yields the items of the given sequence in reverse order.
numbers = [1, 2, 3, 4, 5]
reversed_numbers = list(reversed(numbers))
print(reversed_numbers) # [5, 4, 3, 2, 1]enumerate()
Iterates over a sequence while providing a running index (starting at 0 by default).
for index, value in enumerate(['a', 'b', 'c']):
print(index, value) # 0 a
1 b
2 czip()
Aggregates elements from multiple iterables into tuples. The resulting iterator stops at the shortest input iterable.
names = ['Alice', 'Bob', 'Charlie']
ages = [25, 30, 35]
for name, age in zip(names, ages):
print(f"{name} is {age} years old.")
# Alice is 25 years old.
# Bob is 30 years old.
# Charlie is 35 years old.any(), all()
Evaluate a series of boolean expressions. any() returns True if at least one element is true; all() returns True only if every element is true.
numbers = [0, 1, 2, 3]
print(any(x > 0 for x in numbers)) # True (there are positive numbers)
print(all(x > 0 for x in numbers)) # False (0 is not > 0)map()
Applies a function to each item of an iterable, returning a lazy iterator.
numbers = [1, 2, 3]
# using a lambda to square each number
squared = list(map(lambda x: x**2, numbers))
print(squared) # [1, 4, 9]
# using a built‑in function
uppercase = list(map(str.upper, ['a', 'b', 'c']))
print(uppercase) # ['A', 'B', 'C']filter()
Constructs an iterator from those elements of an iterable for which a predicate function returns True.
numbers = [1, 2, 3, 4, 5]
even_numbers = list(filter(lambda x: x % 2 == 0, numbers))
print(even_numbers) # [2, 4]abs()
Returns the absolute (non‑negative) value of a number.
print(abs(-5)) # 5round()
Rounds a floating‑point number to a given number of decimal places. If the second argument is omitted, it rounds to the nearest integer.
print(round(3.14159, 2)) # 3.14
print(round(2.5)) # 2 (bankers rounding)type()
Returns the type object of the given value.
num = 42
print(type(num)) # <class 'int'>Conclusion
The functions above represent a core subset of Python’s built‑in utilities. Mastering them enables concise, readable code and reduces the need for external libraries when performing everyday programming tasks.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
