Welcome to Day 17 of the 100 Days of Python series!
Python comes packed with a set of powerful, ready-to-use tools known as built-in functions. These functions can save you time, simplify your code, and help you do everything from basic calculations to working with data types — no need to import anything!
Let’s explore some of the most useful built-in functions every Python developer should know.
📦 What You’ll Learn
- What built-in functions are
- Top 20+ built-in functions and how to use them
- Real-world use cases
- Bonus: how to discover more functions
🤔 What Are Built-in Functions?
Built-in functions are predefined functions that are always available in Python. You can use them anytime without importing a module.
Example:
print("Hello, Python!") # ✅ print is a built-in function
🚀 Most Common Built-in Functions (with Examples)
1. print()
– Display output
print("Learning Python!")
2. len()
– Get the length of a string, list, etc.
name = "Python"
print(len(name)) # Output: 6
3. type()
– Find out the data type
print(type(5)) # <class 'int'>
print(type("Hello")) # <class 'str'>
4. int()
, float()
, str()
– Type casting
age = "25"
print(int(age)) # Converts string to integer
5. input()
– Take user input
name = input("Enter your name: ")
print("Hello,", name)
6. sum()
– Add all items in an iterable
numbers = [10, 20, 30]
print(sum(numbers)) # Output: 60
7. max()
/ min()
– Get highest/lowest value
print(max([3, 6, 2])) # 6
print(min([3, 6, 2])) # 2
8. sorted()
– Return a sorted list
print(sorted([5, 2, 9])) # [2, 5, 9]
9. range()
– Generate a sequence of numbers
for i in range(3):
print(i) # 0, 1, 2
10. enumerate()
– Get index while looping
colors = ["red", "blue", "green"]
for index, color in enumerate(colors):
print(index, color)
11. zip()
– Combine iterables element-wise
names = ["Alice", "Bob"]
scores = [85, 92]
for name, score in zip(names, scores):
print(f"{name} scored {score}")
12. abs()
– Absolute value
print(abs(-7)) # 7
13. round()
– Round a number
print(round(3.14159, 2)) # 3.14
14. all()
/ any()
– Test multiple conditions
print(all([True, True, False])) # False
print(any([False, False, True])) # True
15. dir()
– Show attributes/methods of an object
print(dir(str)) # Shows all string methods
16. help()
– Get documentation
help(len) # Shows how len() works
17. eval()
– Execute a string as Python code (⚠️ use with caution)
expression = "3 + 5"
print(eval(expression)) # Output: 8
18. reversed()
– Reverse an iterable
for char in reversed("Python"):
print(char, end="") # nohtyP
19. isinstance()
– Check if a variable is of a type
x = 10
print(isinstance(x, int)) # True
20. map()
/ filter()
– Functional programming helpers
nums = [1, 2, 3]
squared = list(map(lambda x: x**2, nums))
print(squared) # [1, 4, 9]
evens = list(filter(lambda x: x % 2 == 0, nums))
print(evens) # [2]
💡 Bonus Tip: Explore All Built-in Functions
Use this to see all available built-in functions:
print(dir(__builtins__))
🧠 Recap
Today you learned:
- What built-in functions are
- 20+ of the most commonly used ones
- How to use them to write cleaner, faster code
- Where to find documentation using
help()
anddir()
Top comments (0)