CONCEPTS
01Higher-order functions
02Function decorators
03Decorators with arguments
04Yield keyword
05Generators vs iterables
06Generator expressions
SYNTAX_DEMO
Metaprogramming and lazy evaluation
# Decorator
def uppercase_decorator(func):
def wrapper():
result = func()
return result.upper()
return wrapper
@uppercase_decorator
def greet():
return "hello world"
print(greet())
# Generator
def countdown(n):
while n > 0:
yield n
n -= 1
for num in countdown(3):
print(num)