Python Programming Cheat Sheet - Beginner to Intermediate
**1. Basics:**
- Variables: name = "Alice", age = 25
- Data Types: int, float, str, bool, list, tuple, dict, set
- Comments: # Single line, ''' Multi-line '''
**2. Control Flow:**
- Conditional Statements:
if x > 10:
print("Greater than 10")
- Loops:
for i in range(5):
print(i)
while x < 10:
x += 1
**3. Functions:**
def add(a, b):
return a + b
**4. File Operations:**
with open('[Link]', 'r') as file:
content = [Link]()
**5. Modules and Libraries:**
import math
import random
import pandas as pd
import numpy as np
**6. Object-Oriented Programming:**
class Dog:
def __init__(self, name):
[Link] = name
def bark(self):
print([Link] + " says Woof!")
**7. Error Handling:**
try:
result = 10 / 0
except ZeroDivisionError:
print("Cannot divide by zero")