Skip to content
Python Programming

Advanced Python

Beginner Lesson 10 of 10

Take your Python skills to the next level with advanced concepts.

def timer(func):
import time
def wrapper(*args, **kwargs):
start = time.time()
result = func(*args, **kwargs)
print(f"Executed in {time.time() - start:.2f}s")
return result
return wrapper
@timer
def slow_function():
import time
time.sleep(1)
def countdown(n):
while n > 0:
yield n
n -= 1
for num in countdown(5):
print(num)
# Generator expressions
squares = (x**2 for x in range(10))
from contextlib import contextmanager
@contextmanager
def managed_resource():
print("Setup")
yield "resource"
print("Cleanup")
def greet(name: str, age: int = 0) -> str:
return f"Hello {name}, you are {age}"
from typing import List, Dict, Optional
def process(items: List[str]) -> Dict[str, int]:
return {item: len(item) for item in items}
import asyncio
async def fetch_data():
await asyncio.sleep(1)
return "data"
async def main():
result = await fetch_data()
print(result)
asyncio.run(main())

You’ve completed the Python tutorial series! Continue learning with: