✨ Whether you're just starting your Python journey or need a quick refresher, this cheat sheet is your go-to guide in 2025. Clear, simple, and beginner-friendly!
🧠 1. Basic Python Syntax
➤ Printing Something
print("Hello, World!")
➤ Comments
# This is a single-line comment """ This is a multi-line comment """
🔤 2. Variables & Data Types
➤ Variable Assignment
name = "Alice" # string age = 25 # integer height = 5.8 # float is_student = True # boolean
➤ Type Checking
print(type(name)) # <class 'str'>
🔁 3. Conditionals
if age >= 18: print("Adult") elif age >= 13: print("Teen") else: print("Child")
🔄 4. Loops
➤ For Loop
for i in range(5): print(i) # 0 to 4
➤ While Loop
count = 0 while count < 5: print(count) count += 1
📦 5. Data Structures
➤ List
fruits = ["apple", "banana", "cherry"] fruits.append("mango") print(fruits[1]) # banana
➤ Tuple (Immutable)
point = (3, 4)
➤ Set (No duplicates)
unique_nums = {1, 2, 3, 2}
➤ Dictionary (Key-Value)
person = {"name": "Alice", "age": 25} print(person["name"])
🧮 6. Functions
➤ Defining & Calling Functions
def greet(name): print("Hello, " + name) greet("Nivesh")
🛠️ 7. File Handling
➤ Writing to a File
with open("example.txt", "w") as file: file.write("Hello File!")
➤ Reading from a File
with open("example.txt", "r") as file: print(file.read())
🧰 8. Useful Built-In Functions
len("hello") # 5 max([1, 5, 3]) # 5 min([1, 5, 3]) # 1 sorted([3, 1, 2]) # [1, 2, 3] sum([1, 2, 3]) # 6
⚙️ 9. Error Handling
try: x = 5 / 0 except ZeroDivisionError: print("You can't divide by zero!")
🧠 10. Object-Oriented Programming (Basics)
class Person: def __init__(self, name): self.name = name def greet(self): print("Hi, I'm " + self.name) p = Person("Krishna") p.greet()
📌 Bonus: Python Shortcuts and Tricks
# Swap values a, b = 5, 10 a, b = b, a # One-line if status = "Pass" if score >= 50 else "Fail" # List comprehension squares = [i**2 for i in range(5)]
Top comments (0)