To Hero In Python _hot_ — The Complete Python Bootcamp From Zero

def bark(self): return f"{self.name} says woof!" my_dog = Dog("Rex", 3) print(my_dog.bark()) class Animal: def speak(self): pass class Cat(Animal): def speak(self): return "Meow" Magic Methods class Book: def __init__(self, title): self.title = title def __str__(self): return f"Book: {self.title}" 12. Decorators & Generators Decorator (add behavior to functions) def timer(func): import time def wrapper(*args, **kwargs): start = time.time() result = func(*args, **kwargs) print(f"Time: {time.time() - start}") return result return wrapper @timer def long_running_task(): sum(range(1000000)) Generator (yield values lazily) def fibonacci(limit): a, b = 0, 1 while a < limit: yield a a, b = b, a + b for num in fibonacci(100): print(num) 13. Working with Dates & Times from datetime import datetime, timedelta now = datetime.now() print(now.strftime("%Y-%m-%d %H:%M:%S"))