week 4
Week 4: Functional Programming & System Modules
1. Decorators (Function Wrappers)
def decorator(func):
def wrapper():
print("Before function call")
func()
print("After function call")
return wrapper
@decorator
def say_hello():
print("Hello, World!")
say_hello()def repeat(n):
def decorator(func):
def wrapper(*args, **kwargs):
for _ in range(n):
func(*args, **kwargs)
return wrapper
return decorator
@repeat(3)
def greet():
print("Hi!")
greet()2. Generators & Iterators
3. Threading & Multiprocessing
4. Design Patterns
Singleton Pattern
Factory Pattern
Observer Pattern
5. Useful Python Tricks
Summary of Week 4 Topics
Last updated