Python-Class_test_Document
Python-Class_test_Document
🔹 1. Python Basics
python
CopyEdit
age = 25 # Integer
pi = 3.14 # Float
🔹 2. Data Structures
python
CopyEdit
# List
fruits.append("orange")
# Tuple (Immutable)
nums = {1, 2, 3}
# Dictionary
🔹 3. Control Flow
python
CopyEdit
# If-else
print("Adult")
else:
print("Minor")
# Loops
print(fruit)
age -= 1
🔹 4. Functions
python
CopyEdit
def greet(name):
print(greet("Bob"))
python
CopyEdit
class Person:
self.name = name
self.age = age
def greet(self):
p1 = Person("Alice", 30)
p1.greet()
🔹 6. File Handling
python
CopyEdit
data = f.read()
🔹 7. Exception Handling
python
CopyEdit
try:
x=5/0
except ZeroDivisionError:
🔹 8. Useful Tips