Common Built-in Functions in Python: Solve Tasks Faster
Introduction
In this chapter, you will learn common Python built-in functions that appear in everyday coding. These functions help you calculate, convert, inspect, and process data with less code. Mastering them will make your programs cleaner, faster to write, and easier to maintain.
Prerequisites
- Python
3.10+installed - Basic understanding of variables, lists, dictionaries, loops, and functions
- Ability to run
.pyfiles in terminal or IDE
What Are Built-in Functions
Built-in functions are functions available in Python by default, without importing extra modules.
Examples:
print(),input()len(),sum(),max(),min()int(),float(),str()
They are your daily toolkit for handling common programming tasks.
1) Input and Output Functions
print()
Display information on the console.
# Print a simple message
print("Hello, Python!")input()
Read text input from user.
# Read user name as text
name = input("Enter your name: ")
print(f"Welcome, {name}!")2) Type Conversion Functions
These convert values between types.
# Convert text to integer
age = int("18")
# Convert text to float
price = float("19.99")
# Convert number to string
message = str(2026)
print(age, price, message)Warning
Invalid conversion raises ValueError, for example int("abc").
3) Numeric Utility Functions
abs()
Return absolute value.
# Absolute distance from zero
print(abs(-12)) # 12round()
Round number to given precision.
# Round to 2 decimal places
print(round(3.14159, 2)) # 3.14pow()
Power calculation.
# 2 to the power of 5
print(pow(2, 5)) # 324) Sequence and Collection Functions
len()
Get number of elements.
# Length of list
scores = [88, 95, 76]
print(len(scores)) # 3sum()
Sum numeric iterable values.
# Sum scores
scores = [88, 95, 76]
print(sum(scores)) # 259max() and min()
Get largest and smallest values.
# Find highest and lowest score
scores = [88, 95, 76]
print(max(scores)) # 95
print(min(scores)) # 76sorted()
Return a new sorted list.
# Sort values ascending and descending
numbers = [5, 1, 9, 3]
print(sorted(numbers)) # [1, 3, 5, 9]
print(sorted(numbers, reverse=True)) # [9, 5, 3, 1]Tip
Best Practice
Use sorted() when you want to keep original data unchanged.
5) Iteration Helper Functions
range()
Generate integer sequence for loops.
# Print 0 to 4
for i in range(5):
print(i)enumerate()
Get index and value while iterating.
# Print indexed items
fruits = ["apple", "banana", "orange"]
for idx, fruit in enumerate(fruits, start=1):
print(idx, fruit)zip()
Pair multiple iterables together.
# Pair names and scores
names = ["Emma", "Liam", "Noah"]
scores = [95, 88, 91]
for name, score in zip(names, scores):
print(name, score)6) Boolean Check Functions
any()
Return True if at least one element is truthy.
# Check if any score passes 90
scores = [75, 82, 91]
print(any(score >= 90 for score in scores)) # Trueall()
Return True only if all elements are truthy.
# Check if all scores pass 60
scores = [75, 82, 91]
print(all(score >= 60 for score in scores)) # True7) Real Mini Example: Student Score Summary
This example combines several built-in functions in one script.
# Student score list
scores = [88, 95, 76, 92, 85]
# Basic analytics
count = len(scores)
total = sum(scores)
highest = max(scores)
lowest = min(scores)
average = round(total / count, 2)
# Sorted output
sorted_desc = sorted(scores, reverse=True)
# Print report
print("=== Score Summary ===")
print(f"Count: {count}")
print(f"Total: {total}")
print(f"Average: {average}")
print(f"Highest: {highest}")
print(f"Lowest: {lowest}")
print(f"Sorted (desc): {sorted_desc}")This is already a useful pattern for basic reporting tasks.
Common Beginner Mistakes
Mistake 1: Confusing sorted() and .sort()
sorted() returns a new list; .sort() modifies original list in place.
Mistake 2: Using sum() on Non-Numeric Data
Ensure iterable contains numeric values when using sum().
Mistake 3: Forgetting Conversion for input()
input() returns text, so convert before numeric operations.
Surprise Practice Challenge
Build a "Class Quick Analyzer":
- Let user input 5 student names and 5 scores
- Use
zip()to combine them - Print ranking by score (high to low)
- Print class average, max, and min
- Use
any()to check if someone scored 100
If you complete this, you are using built-in functions like an efficient developer.
FAQ
Should I memorize all built-in functions?
No. Start with high-frequency ones (len, sum, max, min, sorted, range, enumerate) and expand naturally.
When should I use enumerate() instead of manual index?
Use enumerate() whenever you need both position and value in a loop. It is cleaner and less error-prone.
Is round() always mathematically intuitive?
Not always for every edge case. For standard beginner tasks, it works well.
Why are built-in functions important?
They reduce boilerplate code and represent Pythonic ways to solve common problems quickly.