5 exercises — decorators, generators, context managers, asyncio/async-await, and type hints. The Python-specific terms you need to discuss code fluently in English.
0 / 30 completed
1 / 30
A code review comment says: "This function would be cleaner as a decorator." In Python, a decorator is:
A decorator in Python is a higher-order function — it wraps another function to add behaviour. Syntax: @decorator_name above the function definition.
Common built-in decorators: • @staticmethod — method that doesn't receive self or cls • @classmethod — method that receives the class (cls) instead of an instance • @property — turns a method into a read-only attribute • @functools.cache / @lru_cache — memoisation
Custom use cases: @app.route() in Flask, @login_required in Django, @retry for automatic retries, @dataclass for auto-generating class methods.
2 / 30
A mentor says: "Use a generator here instead of building the whole list in memory." What is a Python generator and why does it save memory?
A generator uses yield to produce values one at a time. The function's state is suspended between yields and resumed on the next call to next().
Memory benefit: instead of list(range(10_000_000)) — 80+ MB in memory — a generator expression (x for x in range(10_000_000)) uses only a few bytes, because it calculates each value on demand.
Key vocabulary: • yield — produces a value and suspends the function • yield from — delegates to another iterable/generator • lazy evaluation — compute values only when needed • generator expression — (expr for x in iterable) — like a list comprehension but lazy • next(gen) — gets the next value; raises StopIteration when exhausted
3 / 30
A senior engineer reviews your file-reading code and says: "You should use a context manager here." They replace f = open('data.csv') with with open('data.csv') as f:. What does the with statement guarantee?
A context manager implements the context management protocol (__enter__ and __exit__ methods). The with statement calls __exit__ automatically when the block ends — whether normally or due to an exception.
Without with: if an exception occurs before f.close(), the file handle leaks. With enough leaked handles, the OS runs out of file descriptors.
Common context managers: • open() — closes files automatically • threading.Lock() — releases lock even if code raises • tempfile.TemporaryDirectory() — deletes temp dir when done • Database connections/sessions — commits or rolls back • unittest.mock.patch() — restores mocked objects after test
Custom context managers: implement __enter__/__exit__, or use @contextlib.contextmanager with yield.
4 / 30
A job description requires "Python async/await proficiency." A teammate asks: "What does asyncio actually solve?" What is the correct explanation?
asyncio implements cooperative multitasking — a single-threaded event loop that switches between tasks when they are waiting for I/O.
Key vocabulary: • coroutine — a function defined with async def that can be paused with await • event loop — the scheduler that runs coroutines and handles I/O events • await — suspends the current coroutine and hands control back to the event loop • I/O-bound — workloads that spend time waiting for external resources (network, disk, database) — asyncio shines here • CPU-bound — workloads that compute heavily — asyncio doesn't help; use multiprocessing or concurrent.futures.ProcessPoolExecutor
Frameworks built on asyncio: FastAPI, aiohttp, SQLAlchemy (async), asyncpg.
asyncio vs threading: both enable concurrency, but asyncio avoids thread-safety issues (no shared mutable state by default), uses less memory, and scales better for high I/O concurrency.
5 / 30
A tech lead says: "Use type hints and run mypy on this module before merging." What are type hints in Python and why does the team use them?
Type hints (PEP 484+) are optional annotations added to variable, parameter, and return value declarations in Python.
Runtime behaviour: Python ignores type hints by default. They live in __annotations__ but are not enforced. mypy and pyright analyse them statically.
Why teams use type hints: • Catch bugs before runtime (wrong argument type passed to a function) • IDE autocompletion and refactoring support • Documentation that can't go out of date (it's in the code) • Required by some frameworks (FastAPI uses Pydantic models heavily based on type hints)
Code Review Comment: "The `calculate_discount` function could benefit from utilizing a lambda expression for conciseness."
In this context, a lambda expression in Python is best described as:
Lambda expressions are small, anonymous functions defined using the `lambda` keyword. They're ideal for concise operations like calculating discounts – they're designed to be short and simple, unlike regular functions which require a name and full definition. The key difference is their ability to define a function without needing a formal function declaration.
7 / 30
Slack Message: "Hey @john_doe, I'm running into memory issues with this loop. Any suggestions?"
What is a Python generator and how might it help John resolve his issue?
Generators are a key technique for managing memory when dealing with potentially large datasets. Instead of creating an entire list in memory, a generator produces values one at a time as needed, significantly reducing the memory footprint. This is particularly relevant when John's loop might be processing millions of records.
8 / 30
PR Description: "Applying a context manager to this file handling operation ensures proper resource management and prevents potential issues with closing the file."
What does the `with` statement guarantee in Python?
The `with` statement uses context managers to handle resource management, particularly files. It guarantees that the file's resources are properly acquired (opened) and released (closed), even if an exception occurs within the block of code. This prevents resource leaks and ensures proper cleanup.
9 / 30
Standup Update: "I'm working on implementing asynchronous processing using `asyncio` to handle multiple API requests concurrently."
What does `asyncio` actually solve?
`asyncio` is a library that enables writing concurrent code using coroutines. Unlike threads, which create separate processes, `asyncio` allows tasks to run concurrently without the overhead of context switching between them. This is particularly beneficial for I/O-bound operations like network requests.
10 / 30
Code Review Comment: "Let's add type hints to this module. It will improve code readability and help catch potential errors during development."
What are type hints in Python and why does the team use them?
Type hints are annotations added to your Python code that specify the expected data types of variables and function arguments. They don't enforce types at runtime (unless used with a type checker), but they provide valuable information for static analysis tools like `mypy`. This helps catch potential type-related errors early on, improving code quality and maintainability.
11 / 30
Code Review Comment: "The `calculate_discount` function could benefit from utilizing a lambda expression for conciseness."
In this context, a lambda expression in Python is best described as:
Lambda expressions are small, anonymous functions defined using the `lambda` keyword. They're ideal for concise operations like calculating discounts – they're designed to be short and simple, unlike regular functions which require a name and full definition. The key difference is their ability to define a function without needing a formal function declaration.
12 / 30
Slack Message: "Hey @john_doe, I'm running into memory issues with this loop. Any suggestions?"
What is a Python generator and how might it help John resolve his issue?
Generators are a key technique for managing memory when dealing with potentially large datasets. Instead of creating an entire list in memory, a generator produces values one at a time as needed, significantly reducing the memory footprint. This is particularly relevant when John's loop might be processing millions of records.
13 / 30
PR Description: "Applying a context manager to this file handling operation ensures proper resource management and prevents potential issues with closing the file."
What does the `with` statement guarantee in Python?
The `with` statement uses context managers to handle resource management, particularly files. It guarantees that the file's resources are properly acquired (opened) and released (closed), even if an exception occurs within the block of code. This prevents resource leaks and ensures proper cleanup.
14 / 30
Standup Update: "I'm working on implementing asynchronous processing using `asyncio` to handle multiple API requests concurrently."
What does `asyncio` actually solve?
`asyncio` is a library that enables writing concurrent code using coroutines. Unlike threads, which create separate processes, `asyncio` allows tasks to run concurrently without the overhead of context switching between them. This is particularly beneficial for I/O-bound operations like network requests.
15 / 30
Code Review Comment: "Let's add type hints to this module. It will improve code readability and help catch potential errors during development."
What are type hints in Python and why does the team use them?
Type hints are annotations added to your Python code that specify the expected data types of variables and function arguments. They don't enforce types at runtime (unless used with a type checker), but they provide valuable information for static analysis tools like `mypy`. This helps catch potential type-related errors early on, improving code quality and maintainability.
16 / 30
Code Review Comment: "The `calculate_discount` function could benefit from utilizing a lambda expression for conciseness."
In this context, a lambda expression in Python is best described as:
Lambda expressions are small, anonymous functions defined using the `lambda` keyword. They're ideal for concise operations like calculating discounts – they're designed to be short and simple, unlike regular functions which require a name and full definition. The key difference is their ability to define a function without needing a formal function declaration.
17 / 30
Slack Message: "Hey @john_doe, I'm running into memory issues with this loop. Any suggestions?"
What is a Python generator and how might it help John resolve his issue?
Generators are a key technique for managing memory when dealing with potentially large datasets. Instead of creating an entire list in memory, a generator produces values one at a time as needed, significantly reducing the memory footprint. This is particularly relevant when John's loop might be processing millions of records.
18 / 30
PR Description: "Applying a context manager to this file handling operation ensures proper resource management and prevents potential issues with closing the file."
What does the `with` statement guarantee in Python?
The `with` statement uses context managers to handle resource management, particularly files. It guarantees that the file's resources are properly acquired (opened) and released (closed), even if an exception occurs within the block of code. This prevents resource leaks and ensures proper cleanup.
19 / 30
Standup Update: "I'm working on implementing asynchronous processing using `asyncio` to handle multiple API requests concurrently."
What does `asyncio` actually solve?
`asyncio` is a library that enables writing concurrent code using coroutines. Unlike threads, which create separate processes, `asyncio` allows tasks to run concurrently without the overhead of context switching between them. This is particularly beneficial for I/O-bound operations like network requests.
20 / 30
Code Review Comment: "Let's add type hints to this module. It will improve code readability and help catch potential errors during development."
What are type hints in Python and why does the team use them?
Type hints are annotations added to your Python code that specify the expected data types of variables and function arguments. They don't enforce types at runtime (unless used with a type checker), but they provide valuable information for static analysis tools like `mypy`. This helps catch potential type-related errors early on, improving code quality and maintainability.
21 / 30
Code Review Comment: "The `calculate_discount` function could benefit from utilizing a lambda expression for conciseness."
In this context, a lambda expression in Python is best described as:
Lambda expressions are small, anonymous functions defined using the `lambda` keyword. They're ideal for concise operations like calculating discounts – they're designed to be short and simple, unlike regular functions which require a name and full definition. The key difference is their ability to define a function without needing a formal function declaration.
22 / 30
Slack Message: "Hey @john_doe, I'm running into memory issues with this loop. Any suggestions?"
What is a Python generator and how might it help John resolve his issue?
Generators are a key technique for managing memory when dealing with potentially large datasets. Instead of creating an entire list in memory, a generator produces values one at a time as needed, significantly reducing the memory footprint. This is particularly relevant when John's loop might be processing millions of records.
23 / 30
PR Description: "Applying a context manager to this file handling operation ensures proper resource management and prevents potential issues with closing the file."
What does the `with` statement guarantee in Python?
The `with` statement uses context managers to handle resource management, particularly files. It guarantees that the file's resources are properly acquired (opened) and released (closed), even if an exception occurs within the block of code. This prevents resource leaks and ensures proper cleanup.
24 / 30
Standup Update: "I'm working on implementing asynchronous processing using `asyncio` to handle multiple API requests concurrently."
What does `asyncio` actually solve?
`asyncio` is a library that enables writing concurrent code using coroutines. Unlike threads, which create separate processes, `asyncio` allows tasks to run concurrently without the overhead of context switching between them. This is particularly beneficial for I/O-bound operations like network requests.
25 / 30
Code Review Comment: "Let's add type hints to this module. It will improve code readability and help catch potential errors during development."
What are type hints in Python and why does the team use them?
Type hints are annotations added to your Python code that specify the expected data types of variables and function arguments. They don't enforce types at runtime (unless used with a type checker), but they provide valuable information for static analysis tools like `mypy`. This helps catch potential type-related errors early on, improving code quality and maintainability.
26 / 30
Code Review Comment: "The `calculate_discount` function could benefit from utilizing a lambda expression for conciseness."
In this context, a lambda expression in Python is best described as:
Lambda expressions are small, anonymous functions defined using the `lambda` keyword. They're ideal for concise operations like calculating discounts – they're designed to be short and simple, unlike regular functions which require a name and full definition. The key difference is their ability to define a function without needing a formal function declaration.
27 / 30
Slack Message: "Hey @john_doe, I'm running into memory issues with this loop. Any suggestions?"
What is a Python generator and how might it help John resolve his issue?
Generators are a key technique for managing memory when dealing with potentially large datasets. Instead of creating an entire list in memory, a generator produces values one at a time as needed, significantly reducing the memory footprint. This is particularly relevant when John's loop might be processing millions of records.
28 / 30
PR Description: "Applying a context manager to this file handling operation ensures proper resource management and prevents potential issues with closing the file."
What does the `with` statement guarantee in Python?
The `with` statement uses context managers to handle resource management, particularly files. It guarantees that the file's resources are properly acquired (opened) and released (closed), even if an exception occurs within the block of code. This prevents resource leaks and ensures proper cleanup.
29 / 30
Standup Update: "I'm working on implementing asynchronous processing using `asyncio` to handle multiple API requests concurrently."
What does `asyncio` actually solve?
`asyncio` is a library that enables writing concurrent code using coroutines. Unlike threads, which create separate processes, `asyncio` allows tasks to run concurrently without the overhead of context switching between them. This is particularly beneficial for I/O-bound operations like network requests.
30 / 30
Code Review Comment: "Let's add type hints to this module. It will improve code readability and help catch potential errors during development."
What are type hints in Python and why does the team use them?
Type hints are annotations added to your Python code that specify the expected data types of variables and function arguments. They don't enforce types at runtime (unless used with a type checker), but they provide valuable information for static analysis tools like `mypy`. This helps catch potential type-related errors early on, improving code quality and maintainability.
What does the "Python Vocabulary" vocabulary exercise cover?
This exercise tests real IT vocabulary related to python vocabulary through 30 multiple-choice questions, each built from realistic workplace sentences rather than abstract definitions.
Is this vocabulary exercise free to use?
Yes. Every exercise on CoderSlingo, including this one, is completely free — no account, sign-up, or payment required.
How many questions does this exercise have?
This exercise has 30 questions. Each one shows a real-world sentence or scenario with multiple-choice options and an explanation once you answer.
What happens after I answer a question?
You'll see immediate feedback showing whether your answer was correct, along with a short explanation of why — then a button to move to the next question, and a full results screen at the end.
Can I retry the exercise if I get questions wrong?
Yes. Once you reach the results screen, click "Try again" to reset your answers and go through the exercise from the start as many times as you like.
Do I need to create an account to take this exercise?
No account is needed. Your answers are scored in your browser during the session — nothing is saved to a server, so you can jump straight in.
Is my progress saved if I leave the page?
No — progress within an exercise resets if you navigate away or reload. Each exercise is short enough to complete in a few minutes in one sitting.
Are these vocabulary exercises connected to other topics?
Yes — browse the full vocabulary exercises hub to find related modules covering adjacent IT topics and roles.
How is this different from reading a glossary or blog article?
Exercises like this one are active recall drills — you have to choose the correct term or phrasing yourself, which builds retention faster than passively reading a definition.
Where can I find more vocabulary exercises?
Browse the full Vocabulary exercises hub for hundreds of modules covering Agile, DevOps, security, databases, architecture, and more — organised by IT role and skill.