Python Built-in Functions
Essential functions that come ready to use in Python
🔧 Built-in Functions
Python comes with many useful functions ready to use. No need to install anything - they're always available!
# Common built-in functions
print("Hello!") # Display text
len("Python") # Get length: 6
type(42) # Check type: int
max(1, 5, 3) # Find biggest: 5
68+
Functions
Ready
To Use
No
Import Needed
🌟 Most Common Functions
print()
Show text on screen
print("Hello World!")
print(42)
print("Age:", 25)
len()
Count items or characters
len("Hello") # 5
len([1, 2, 3]) # 3
len({"a": 1}) # 1
type()
Check what type something is
type(42) # int
type("hi") # str
type([1, 2]) # list
input()
Get text from user
name = input("Your name: ")
age = input("Your age: ")
print(f"Hi {name}!")
🔹 Number Functions
Math Operations
# Find biggest and smallest
max(5, 2, 8, 1) # 8
min(5, 2, 8, 1) # 1
# Add all numbers
sum([1, 2, 3, 4]) # 10
# Absolute value (remove minus sign)
abs(-5) # 5
abs(3) # 3
Rounding Numbers
# Round to nearest whole number
round(3.7) # 4
round(3.2) # 3
# Round to specific decimal places
round(3.14159, 2) # 3.14
Number Ranges
# Create number sequences
list(range(5)) # [0, 1, 2, 3, 4]
list(range(2, 6)) # [2, 3, 4, 5]
list(range(0, 10, 2)) # [0, 2, 4, 6, 8]
🔹 Text Functions
Convert to Text
# Turn anything into text
str(42) # "42"
str(3.14) # "3.14"
str(True) # "True"
Check Text Content
# Check if text contains only numbers
"123".isdigit() # True
"12a".isdigit() # False
# Check if text contains only letters
"Hello".isalpha() # True
"Hi123".isalpha() # False
🔹 List Functions
Create Lists
# Make a list
list("abc") # ['a', 'b', 'c']
list(range(3)) # [0, 1, 2]
Sort Lists
# Sort items
sorted([3, 1, 4]) # [1, 3, 4]
sorted(["c", "a"]) # ['a', 'c']
# Reverse order
reversed([1, 2, 3]) # [3, 2, 1]
Work with Items
# Check if item exists
"apple" in ["apple", "banana"] # True
# Get all items with their position
list(enumerate(["a", "b"])) # [(0, 'a'), (1, 'b')]
🔹 Type Conversion
Convert to Numbers
# Text to number
int("42") # 42
float("3.14") # 3.14
# Number to different type
int(3.9) # 3 (removes decimal)
float(5) # 5.0
Convert to True/False
# Check if something is true or false
bool(1) # True
bool(0) # False
bool("hi") # True
bool("") # False
🔹 File Functions
Open Files
# Read a file
with open("data.txt", "r") as file:
content = file.read()
print(content)
# Write to a file
with open("output.txt", "w") as file:
file.write("Hello, file!")