Every Python developer needs a good cheat sheet. Whether you’re a complete beginner trying to remember how loops work, or an experienced coder who just needs a quick syntax reminder, a Python cheat sheet saves you from Googling the same thing over and over.
So I built this one to be genuinely complete. Below you’ll find every essential piece of Python syntax — variables, data types, strings, lists, dictionaries, loops, functions, and more — all organized in one place with clear examples. Furthermore, you can download the whole thing as a free PDF to keep beside you while you code.
Let’s dive in.
Download the Python Cheat Sheet PDF (Free)
Want this entire cheat sheet as a printable PDF? You can download it for free — no email, no signup, no cost. Keep it open while you code, print it, or save it to your phone. Then, use the reference sections below to learn each part.
Python Basics & Printing
First, let’s cover the absolute basics — printing output and adding comments.
# This is a comment
print("Hello, World!") # prints text
print(5 + 3) # prints 8
name = "Ali"
print(f"Hi {name}") # f-string: Hi Ali
Variables & Data Types
Next, variables store data. Python figures out the type automatically.
x = 10 # int (integer)
y = 3.14 # float (decimal)
name = "Sara" # str (string)
is_active = True # bool (boolean)
items = [1, 2, 3] # list
type(x) # check the type → int
Strings & String Methods
Strings are text. Here are the most useful string operations you’ll use constantly.
text = "Python"
len(text) # 6 (length)
text.upper() # "PYTHON"
text.lower() # "python"
text.replace("P","J")# "Jython"
text[0] # "P" (first character)
text[-1] # "n" (last character)
text[0:3] # "Pyt" (slicing)
"a,b,c".split(",") # ['a', 'b', 'c']
"-".join(["a","b"]) # "a-b"
Numbers & Math Operations
Python handles math easily. Here are the core operators and functions.
10 + 3 # 13 (addition)
10 - 3 # 7 (subtraction)
10 * 3 # 30 (multiplication)
10 / 3 # 3.33 (division)
10 // 3 # 3 (floor division)
10 % 3 # 1 (remainder/modulo)
10 ** 3 # 1000 (power)
abs(-5) # 5
round(3.7)# 4
max(1,5,3)# 5
min(1,5,3)# 1
Lists
Lists store multiple items in order. They’re one of the most-used data structures in Python.
fruits = ["apple", "banana", "cherry"]
fruits[0] # "apple"
fruits.append("mango") # add to end
fruits.insert(1,"kiwi")# add at position
fruits.remove("banana")# remove item
fruits.pop() # remove & return last
len(fruits) # length
fruits.sort() # sort the list
fruits.reverse() # reverse order
"apple" in fruits # True/False check
Dictionaries
Dictionaries store data as key-value pairs. They’re perfect for structured data.
student = {"name": "Ali", "age": 20}
student["name"] # "Ali"
student["city"] = "Lahore" # add new key
student.keys() # all keys
student.values() # all values
student.items() # all key-value pairs
student.get("age") # 20 (safe access)
del student["age"] # delete a key
Tuples & Sets
Tuples are like lists but cannot be changed. Sets store unique values only.
# Tuple (immutable)
coords = (10, 20)
coords[0] # 10
# Set (unique values only)
nums = {1, 2, 2, 3} # {1, 2, 3}
nums.add(4) # add item
nums.remove(1) # remove item
Conditions (if / elif / else)
Conditions let your program make decisions based on data.
age = 18
if age >= 18:
print("Adult")
elif age >= 13:
print("Teenager")
else:
print("Child")
# Comparison operators:
# == equal != not equal
# > greater < less than
# >= >= equal <= <= equal
# and or not (logical operators)
Loops (for & while)
Loops repeat code. The for loop iterates over items; the while loop runs until a condition is false.
# For loop
for i in range(5): # 0 to 4
print(i)
for fruit in fruits: # loop a list
print(fruit)
# While loop
count = 0
while count < 5:
print(count)
count += 1
# Loop control
break # exit the loop
continue # skip to next iteration
Functions
Functions are reusable blocks of code. They make your programs organized and DRY (Don’t Repeat Yourself).
# Basic function
def greet(name):
return f"Hello {name}"
greet("Sara") # "Hello Sara"
# Default parameter
def power(base, exp=2):
return base ** exp
power(3) # 9
power(3, 3) # 27
# *args and **kwargs
def add(*numbers):
return sum(numbers)
add(1, 2, 3) # 6
# Lambda (anonymous function)
square = lambda x: x * x
square(5) # 25

List Comprehensions
List comprehensions create lists in a single, clean line. They’re a hallmark of good Python code.
# Basic
squares = [x*x for x in range(5)]
# [0, 1, 4, 9, 16]
# With condition
evens = [x for x in range(10) if x % 2 == 0]
# [0, 2, 4, 6, 8]
File Handling
Python makes reading and writing files simple with the open() function.
# Read a file
with open("file.txt", "r") as f:
content = f.read()
# Write to a file
with open("file.txt", "w") as f:
f.write("Hello")
# Append to a file
with open("file.txt", "a") as f:
f.write("More text")
Error Handling
Error handling prevents your program from crashing when something goes wrong.
try:
result = 10 / 0
except ZeroDivisionError:
print("Cannot divide by zero")
except Exception as e:
print(f"Error: {e}")
else:
print("No errors")
finally:
print("Always runs")
Classes & Objects (OOP)
Object-oriented programming lets you create your own data types using classes.
class Dog:
def __init__(self, name):
self.name = name
def bark(self):
return f"{self.name} says woof!"
my_dog = Dog("Rex")
my_dog.bark() # "Rex says woof!"
Useful Built-in Functions
| Function | What It Does |
|---|---|
| len() | Length of a string, list, etc. |
| type() | Returns the data type |
| range() | Generates a sequence of numbers |
| sum() | Adds all items in a list |
| sorted() | Returns a sorted list |
| input() | Gets user input |
| int(), str(), float() | Convert between types |
| enumerate() | Loop with index numbers |
| zip() | Combine two lists together |
How to Use This Python Cheat Sheet Effectively
A cheat sheet works best as a quick reference, not a replacement for practice. Therefore, keep it open in a tab while you code. When you forget a syntax, glance at it instead of breaking your flow to search online. Over time, you’ll memorize most of it naturally.
Moreover, try retyping each snippet into your own editor. Active typing builds memory far better than passive reading. For beginners, work through the sections in order — basics first, then loops and functions, then OOP.
Final Thoughts
This Python cheat sheet covers everything you need for day-to-day coding — from your very first print statement to classes and error handling. Bookmark this page, download the PDF, and keep it close while you learn.
Above all, remember that a cheat sheet supports your learning but doesn’t replace doing. Practice each concept, build small projects, and refer back here whenever you need a quick reminder. With consistent practice and this reference at your side, you’ll be writing confident Python code in no time.
Found this cheat sheet helpful? Is there a Python command you’d like me to add? Drop a comment below — I read and reply to every one!
Frequently Asked Questions (FAQ)
You can download the complete Python cheat sheet PDF for free directly from this page — no signup or payment required. It includes all essential Python syntax organized by topic, making it perfect for printing or keeping on your phone while coding.
Yes, a Python cheat sheet is extremely helpful for beginners. It provides a clear overview of all core syntax in one place, which reduces the need to search for basic commands constantly. This lets beginners focus on building and practicing rather than memorizing every detail at once.
A complete Python cheat sheet should include variables and data types, string methods, math operations, lists, dictionaries, tuples, sets, conditions, loops, functions, list comprehensions, file handling, error handling, and basic object-oriented programming with classes.
A cheat sheet is a reference tool, not a complete learning resource. While it’s excellent for quickly recalling syntax, learning Python properly requires practice, projects, and a structured course or book. Use a cheat sheet alongside hands-on coding for the best results.
The fastest way to memorize Python syntax is through active practice — retype the examples yourself rather than just reading them, build small projects, and refer to a cheat sheet only when stuck. Repetition through actual coding cements the syntax in your memory naturally over time.



