🐍PyQuiz
Which of these are NOT objects in Python?
Which of these are NOT objects in Python?
Anonymous Quiz
15%
Functions
11%
Classes
34%
Modules
41%
None
Closures: Functions That Remember
Closures can be mystifying. Imagine a function inside another function, and the inner function remembers the outer function’s variables, even after the outer function has finished running.
Closures capture variables by reference, which is why beginners often stumble when using loops inside closures. They’re powerful once you understand that the inner function “remembers” its environment.
Closures can be mystifying. Imagine a function inside another function, and the inner function remembers the outer function’s variables, even after the outer function has finished running.
Closures capture variables by reference, which is why beginners often stumble when using loops inside closures. They’re powerful once you understand that the inner function “remembers” its environment.
❤2
🐍 PyQuiz
A Python function with no return statement actually returns:
A Python function with no return statement actually returns:
Anonymous Quiz
14%
0
22%
False
34%
None
30%
Nothing
🐍 PyQuiz
If Python can't find a variable locally, what's the next place it looks?
If Python can't find a variable locally, what's the next place it looks?
Anonymous Quiz
52%
Global
22%
Built-in
22%
Parent scope
5%
None
👏1
🐍 PyQuiz
A decorator in Python is essentially:
A decorator in Python is essentially:
Anonymous Quiz
16%
A class that modifies code
73%
A function that takes another function
6%
A syntax sugar for loops
5%
A compile-time feature
👍1
Context Managers: The “Clean-Up Crew” of Python
Ever forget to close a file and wonder why your program is misbehaving?
Context managers prevent this headache.
When you use with, Python ensures that resources are properly acquired and released automatically. Think of it as hiring a clean-up crew: they take care of the dirty work while you focus on the important tasks.
You don’t have to remember to call f.close(). This small pattern prevents bugs, improves readability, and is a hallmark of professional Python code.
Ever forget to close a file and wonder why your program is misbehaving?
Context managers prevent this headache.
When you use with, Python ensures that resources are properly acquired and released automatically. Think of it as hiring a clean-up crew: they take care of the dirty work while you focus on the important tasks.
with open('data.txt') as f:
data = f.read()
# file is automatically closed hereYou don’t have to remember to call f.close(). This small pattern prevents bugs, improves readability, and is a hallmark of professional Python code.
❤4
🐍 PyQuiz
In Python, arguments are passed by:
In Python, arguments are passed by:
Anonymous Quiz
36%
Value
30%
Reference
32%
Object reference
2%
Copy
await Is Not Optional in Async
💻 You’re racing 10 API calls with asyncio… and it still takes 10 seconds. Sound familiar?
✅ Fix: await every I/O. Swap requests for httpx (same API, truly async).
▶️ Now 10 calls = 1 second.
💻 You’re racing 10 API calls with asyncio… and it still takes 10 seconds. Sound familiar?
async def fetch():
return requests.get(url).json() # ← Blocks the entire event loop✅ Fix: await every I/O. Swap requests for httpx (same API, truly async).
import httpx
async def fetch():
async with httpx.AsyncClient() as client:
r = await client.get(url)
return r.json()▶️ Now 10 calls = 1 second.
❤2
How do you learn Python BEST?
Anonymous Poll
21%
Reading documentation/books
32%
Video tutorials
44%
Building projects
4%
Visual Materials/Images