Python Cheat Sheet
Python Cheat Sheet
1. Basic Syntax
# This is a comment
print("Hello World")
age = 25 # Integer
print("Hello,", username)
4. Operators
# Math: +, -, *, /, %, //, **
5. Conditional Statements
age = 18
else:
print("You are a minor.")
6. Loops
For Loop:
for i in range(5):
print(i)
While Loop:
count = 0
print(count)
count += 1
7. Functions
def greet(name):
print("Hello", name)
greet("John")
8. Data Structures
List:
Dictionary:
Tuple:
Set:
numbers = {1, 2, 3, 4}
9. File Handling
Write:
file.write("Hello World")
file.close()
Read:
print(file.read())
file.close()
try:
print(100 / age)
except ZeroDivisionError:
except ValueError:
print("Invalid input.")
finally:
print("Done.")
import math
print(math.sqrt(16))
12. Mini Project Ideas
- Calculator
- To-Do App
- Password Generator
- Quiz Game
- File Organizer
Week 1: Basics
Practice Tip: