🐍 Python Cheatsheet (Quick Reference Guide)
This Python Cheatsheet is a compact and structured reference for beginners, developers, and interview preparation.
It covers all essential topics of Python in a simple and fast-to-revise format.
🟢 1. Basic Syntax
print("Hello, World!")
- Indentation is important
- No semicolons required
- Case-sensitive language
🟢 2. Variables
x = 10
name = "Python"
- No declaration needed
- Dynamically typed
🟢 3. Data Types
- int → 10
- float → 10.5
- str → "text"
- bool → True / False
- list → [1, 2, 3]
- tuple → (1, 2, 3)
- dict → {"a": 1}
- set → {1, 2, 3}
🟢 4. Operators
Arithmetic
+ - * / // %
Comparison
== != > < >= <=
Logical
and, or, not
🟢 5. Conditional Statements
if x > 10:
print("Greater")
elif x == 10:
print("Equal")
else:
print("Smaller")
🟢 6. Loops
For Loop
for i in range(5):
print(i)
While Loop
i = 0
while i < 5:
i += 1
🟢 7. Functions
def add(a, b):
return a + b
-
Defined using
def - Supports return values
🟢 8. Lists
nums = [1, 2, 3]
nums.append(4)
Common Methods:
- append()
- insert()
- remove()
- pop()
- sort()
🟢 9. Tuples
t = (1, 2, 3)
- Immutable
- Faster than lists
🟢 10. Dictionaries
data = {"name": "John", "age": 25}
Methods:
- keys()
- values()
- items()
🟢 11. Sets
s = {1, 2, 3}
- Unique elements only
- Unordered
🟡 12. Object-Oriented Programming (OOP)
class Person:
def __init__(self, name):
self.name = name
Concepts:
- Class
- Object
- Inheritance
- Polymorphism
- Encapsulation
🟡 13. Exception Handling
try:
x = 10 / 0
except ZeroDivisionError:
print("Error occurred")
finally:
print("Done")
🔵 14. File Handling
with open("file.txt", "r") as f:
data = f.read()
Modes:
- r → read
- w → write
- a → append
🔵 15. Modules & Imports
import math
print(math.sqrt(16))
🔵 16. Advanced Concepts
- Decorators
- Generators
- Context Managers
- Coroutines (async/await)
- Data Model (magic methods)
All are advanced features of Python.
🧠 17. Built-in Functions
- print()
- len()
- type()
- input()
- range()
- sum()
- max()
- min()
⚡ 18. Quick Tips
- Use meaningful variable names
- Follow PEP 8 style guide
- Prefer list comprehensions
- Use virtual environments
- Write readable code
📊 Summary
This Python Cheatsheet provides a fast and structured reference for all essential programming concepts including syntax, data structures, OOP, and advanced topics in Python.
🚀 Conclusion
This cheatsheet is designed for quick revision, interviews, and daily development work in Python.
Keep it as your daily reference guide to improve coding speed and understanding.


0 Comments