W3Reference.com
Toggle Menu
Home
Online Rust Compiler
Tutorials
Python Tutorial
Java Tutorial
Rust Tutorial
TypeScript Tutorial
ReactJS Tutorial
HTML & CSS Basics
Docker Containers Guide
Kubernetes Tutorial
Software Design Patterns
Blog
All Posts
Advanced Python Concepts
Evaluate your knowledge of decorators,generators,and context managers.
1. What is the primary purpose of a Python decorator?
To modify the behavior of a function or class
To speed up code execution
To handle exceptions
To create new data types
2. Which keyword is used to create a generator function in Python?
yield
generate
return
yield from
3. Which module is used to define type hints in Python 3.5+?
typing
types
hint
typehint
4. Which methods must a class implement to act as a context manager with the 'with' statement?
__enter__ and __exit__
__context__
__manage__
__with__
5. What is a metaclass in Python?
A class that creates classes
A subclass of a base class
A class with multiple inheritance
A class that cannot be instantiated
6. Which of the following are functional programming constructs in Python?
lambda
map
filter
for loop
list comprehension
7. Which exceptions are subclasses of OSError?
FileNotFoundError
ValueError
IOError
ImportError
PermissionError
8. Which statements about generators are true?
Generators are a type of iterator
Generators use the 'yield' keyword
Generators store all values in memory
Generator expressions are created with parentheses
Generators cannot be restarted
9. What are consequences of the Global Interpreter Lock (GIL) in CPython?
Only one thread executes Python bytecode at a time
Multiprocessing is preferred for CPU-bound tasks
I/O-bound tasks benefit from multithreading
The GIL is removed in Python 3.10+
The GIL improves memory safety
10. A Python decorator can modify the return value of a decorated function.
True
False
11. Python supports multiple inheritance (a class inheriting from multiple parent classes).
True
False
12. Asyncio is primarily used for CPU-bound tasks in Python.
True
False
13. What term describes a function that returns an iterator and uses the 'yield' keyword?
14. What does the acronym 'GIL' stand for in Python?
15. Name the built-in function that returns tuples of (index, value) for an iterable.
Reset
Answered 0 of 0 — 0 correct