1 Which of the following summarizes the core philosophy expressed in the Zen of Python? A "Code density is better than readability." B "Performance is better than clarity. Concurrency is better than simplicity." C "Implicit is better than explicit. Complex is better than simple." D "Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Readability counts."
View answer & explanationFull Screen Mode →
2 What happens to 'assert' statements when Python is run with the '-O' (optimize) command-line flag? A Assert failures print warnings instead of raising AssertionError. B Asserts are converted into unit tests. C All 'assert' statements are completely removed and ignored by the compiler, producing zero bytecode instructions. D An error is raised.
View answer & explanationFull Screen Mode →
3 What is the '__debug__' built-in constant in Python? A A function that enables the interactive debugger. B A boolean constant that is True by default, but is permanently set to False when Python is run with the '-O' (optimize) flag. C A flag that prints memory leaks to the terminal. D A variable that tracks total exceptions.
View answer & explanationFull Screen Mode →
4 What is 'IronPython'? A An implementation of the Python programming language targeting the .NET Framework and CLR. B A Python library for hardware robotics. C A security tool for hardening Python scripts. D A compiler for Ironclad systems.
View answer & explanationFull Screen Mode →
5 What is 'Jython'? A A Python library for quantum computing. B A JavaScript compiler written in Python. C A Python binding for JSON. D An implementation of the Python programming language designed to run on the Java platform (JVM).
View answer & explanationFull Screen Mode →
6 What is 'CPython' as opposed to the Python language itself? A A version of Python optimized for cyber-security. B A compiler that translates C into Python. C The standard reference implementation of the Python programming language written in C. D A legacy version of Python 1.0.
View answer & explanationFull Screen Mode →
7 What is 'PEP 703' in the Python community? A Introducing the walrus operator. B Making the Global Interpreter Lock (GIL) optional in CPython (free-threaded Python). C Replacing Python 3 with Python 4. D Deprecating the threading module.
View answer & explanationFull Screen Mode →
8 What does 'compile(source, filename, mode)' do in Python? A Compiles source code text into a code object that can subsequently be executed by exec() or evaluated by eval(). B Compiles Python code into a native Windows .exe executable. C Compiles Python into C++ code. D Checks spelling in code comments.
View answer & explanationFull Screen Mode →
9 What is the output of 'delattr(obj, "name")'? A Error B Sets obj.name to None. C Removes all attributes from obj. D Deletes the attribute 'name' from obj (equivalent to 'del obj.name').
View answer & explanationFull Screen Mode →
10 What is the output of 'setattr(obj, "name", "Bob")'? A Creates a new class named Bob. B Returns 'Bob'. C Assigns the value 'Bob' to obj.name and returns None. D Error
View answer & explanationFull Screen Mode →
11 What does 'locals()' return inside a Python function? A A list of local variable names. B A dictionary representing the current local namespace symbol table. C The activation frame pointer. D The function arguments as a tuple.
View answer & explanationFull Screen Mode →
12 What does 'globals()' return in Python? A A dictionary representing the current global module namespace symbol table. B A list of all global variables across all loaded modules. C A list of environment variables. D The memory addresses of global variables.
View answer & explanationFull Screen Mode →
13 What does 'asyncio.wait_for(fut, timeout)' do? A Retries the future multiple times. B Pauses the event loop for timeout seconds. C Sets the CPU timeout threshold. D Waits for the future or coroutine to complete, raising asyncio.TimeoutError (or TimeoutError in 3.11+) if it exceeds timeout seconds.
View answer & explanationFull Screen Mode →
14 What is the purpose of 'async with' and 'async for' in asynchronous Python? A They compile loops into C extensions. B They run synchronous loops in multithreaded mode. C 'async with' operates on asynchronous context managers (__aenter__/__aexit__), and 'async for' operates on asynchronous iterators (__aiter__/__anext__). D They measure loop execution time.
View answer & explanationFull Screen Mode →
15 What does 'task.cancel()' do to a running asyncio Task? A Immediately kills the process. B Arranges for an asyncio.CancelledError exception to be thrown into the coroutine on the next event loop iteration. C Pauses the task indefinitely. D Deletes the task object.
View answer & explanationFull Screen Mode →
16 What is the output of 'asyncio.create_task(coro())'? A Wraps the coroutine into an asyncio.Task and schedules its execution on the active event loop, returning the Task object. B Executes the coroutine synchronously immediately. C Spawns a new OS thread. D Cancels the coroutine.
View answer & explanationFull Screen Mode →
17 What does 'asyncio.iscoroutinefunction(func)' return? A True if func has zero parameters. B True if func is currently executing on an event loop. C True if func has completed execution. D True if func was defined using 'async def'; False otherwise.
View answer & explanationFull Screen Mode →
18 What is the difference between 'threading.Semaphore' and 'threading.BoundedSemaphore'? A A BoundedSemaphore works across processes. B A standard Semaphore can only have a value of 1. C A BoundedSemaphore raises a ValueError if release() is called more times than its initial acquire counter value, preventing accidental over-releases. D There is no difference.
View answer & explanationFull Screen Mode →
19 What does 'threading.Event' provide for thread synchronization? A A counter that counts how many threads have completed. B A simple flag mechanism where threads can wait() until another thread calls set() to notify them. C A lock that expires automatically. D An asynchronous event loop.
View answer & explanationFull Screen Mode →
20 What does 'threading.current_thread().name' return? A The string name of the currently executing thread (e.g., 'MainThread' or 'Thread-1'). B The thread ID as an integer. C The memory address of the thread object. D The process ID.
View answer & explanationFull Screen Mode →
21 In Python multiprocessing on Windows and macOS, what is the default process start method, and why is 'if __name__ == "__main__":' required? A 'thread': processes are converted into threads. B 'fork': the child process clones memory directly without importing. C 'exec': the script is replaced in memory. D 'spawn': a fresh Python process is launched and re-imports the main script, requiring the guard to prevent infinite process creation loops.
View answer & explanationFull Screen Mode →
22 What does 'multiprocessing.Queue' provide that standard 'queue.Queue' does NOT? A It stores items directly in database tables. B It is faster than queue.Queue. C It safely serializes (pickles) objects across process boundaries via IPC pipes, making it multi-process safe. D It allows only integers to be stored.
View answer & explanationFull Screen Mode →
23 What major optimization was introduced in Python 3.11 as part of the Faster CPython project (PEP 659)? A Complete removal of the GIL. B A Specializing Adaptive Interpreter that dynamically detects monomorphic bytecodes at runtime and specializes them into faster specialized opcodes. C Replacing Python bytecode with WebAssembly. D Automatic conversion of all loops into C++ code.
View answer & explanationFull Screen Mode →
24 What is 'Cython'? A A programming language and compiler that translates Python code augmented with static C type declarations directly into high-performance C/C++ extensions. B A pure C compiler for Linux. C An asynchronous web framework. D A database driver for SQLite.
View answer & explanationFull Screen Mode →
25 What is 'PyPy' in the Python ecosystem? A A lightweight version of Python for microcontrollers. B The official Python package manager. C A Python static type checker. D A fast, compliant alternative implementation of Python written in RPython that features a Just-In-Time (JIT) compiler.
View answer & explanationFull Screen Mode →
26 What is the security hazard of using 'eval()' or 'exec()' on unvalidated user input? A It turns off the computer's firewall. B It causes an automatic CPU hardware short circuit. C Arbitrary Code Execution: an attacker can execute malicious commands (e.g., __import__('os').system('rm -rf /')) to compromise the entire host system. D It deletes all global variables.
View answer & explanationFull Screen Mode →
27 What does built-in function 'exec(code)' do? A Evaluates an expression and returns its result. B Dynamically executes arbitrary Python statements, loops, classes, or code blocks, always returning None. C Executes an external shell bash script. D Spawns a new operating system process.
View answer & explanationFull Screen Mode →
28 What does built-in function 'eval(expression)' do in Python? A Parses and evaluates a single dynamic Python expression string and returns the evaluated result. B Executes arbitrary multi-line Python statements. C Checks if a variable is valid. D Compiles code to a .pyc file.
View answer & explanationFull Screen Mode →
29 What bytecode instruction is generated when a local variable is read inside a CPython function? A LOAD_CONST B LOAD_GLOBAL C LOAD_NAME D LOAD_FAST
View answer & explanationFull Screen Mode →
30 What does Python's 'dis' module do? A Disconnects network sockets. B Disables garbage collection during profiling. C Disassembles Python bytecode into human-readable mnemonics (opcodes). D Distributes tasks across multiple servers.
View answer & explanationFull Screen Mode →
31 What is the difference between a 'Data Descriptor' and a 'Non-Data Descriptor' in Python? A A Data Descriptor stores numbers, while a Non-Data Descriptor stores strings. B A Data Descriptor defines '__set__' (and/or '__delete__'), taking precedence over an instance's '__dict__'; a Non-Data Descriptor defines only '__get__', which is overridden by an instance's '__dict__'. C A Non-Data Descriptor is thread-safe, while a Data Descriptor is not. D There is no difference.
View answer & explanationFull Screen Mode →
32 What is the 'Descriptor Protocol' in Python? A A protocol implemented by objects defining at least one of the methods __get__(), __set__(), or __delete__(), customizing attribute access on classes. B A protocol for serializing objects to XML. C A network communication protocol for remote Python calls. D A format for describing docstrings in Markdown.
View answer & explanationFull Screen Mode →
33 What hook method introduced in Python 3.6 (PEP 487) provides a simpler alternative to metaclasses for customizing subclass creation? A __inherit__(cls) B __new_subclass__(cls) C __subclass_init__(cls) D __init_subclass__(cls, **kwargs)
View answer & explanationFull Screen Mode →
34 How do you specify a custom metaclass 'Meta' for a class 'A' in Python 3? A @meta(Meta) class A: B class A: __metaclass__ = Meta C class A(metaclass=Meta): D class A extends Meta:
View answer & explanationFull Screen Mode →
35 How do you dynamically create a new class 'MyClass' inheriting from 'object' with attribute 'x=10' using the 3-argument 'type()' constructor? A MyClass = type('MyClass', object, {'x': 10}) B MyClass = type('MyClass', (object,), {'x': 10}) C MyClass = type.create('MyClass', {'x': 10}) D MyClass = new type('MyClass', (object,), {'x': 10})
View answer & explanationFull Screen Mode →
36 In Python, what is a 'Metaclass'? A The class of a class: a class whose instances are classes themselves, defining how classes are constructed and instantiated. B An abstract base class that cannot be inherited. C A class that defines database metadata. D A C extension module that defines new primitive types.
View answer & explanationFull Screen Mode →
37 What is 'concurrent.futures.ProcessPoolExecutor'? A A compiler that translates Python into C. B A thread manager for GUI applications. C A memory cache for multiprocessing queues. D A high-level interface that executes callables asynchronously using a pool of worker processes, bypassing the GIL for CPU-bound parallelism.
View answer & explanationFull Screen Mode →
38 What is 'concurrent.futures.ThreadPoolExecutor'? A A tool for executing unit tests in parallel. B A thread that monitors memory leaks. C A high-level interface for asynchronously executing callables using a pool of reusable worker threads. D A real-time operating system scheduler.
View answer & explanationFull Screen Mode →
39 How can you run a blocking synchronous function 'sync_task()' inside an asyncio application without blocking the event loop? A await sync_task() B await asyncio.to_thread(sync_task) (Python 3.9+) or loop.run_in_executor() C asyncio.spawn(sync_task) D asyncio.block(sync_task)
View answer & explanationFull Screen Mode →
40 What happens if you run a blocking, CPU-heavy operation (e.g., time.sleep(5) or heavy math) directly inside an 'asyncio' coroutine? A It blocks the entire event loop thread, preventing all other concurrent coroutines from executing for 5 seconds. B The event loop automatically offloads the blocking call to a new thread. C It raises an AsyncBlockedException. D It executes in the background without affecting other tasks.
View answer & explanationFull Screen Mode →
41 What does 'asyncio.gather(*aws)' do? A Kills all running coroutines. B Executes coroutines sequentially one after another. C Gathers garbage collection data across coroutines. D Runs multiple awaitable objects concurrently on the event loop and returns a list of their results aggregated in the original order.
View answer & explanationFull Screen Mode →
42 What function is the standard high-level entry point to execute an async coroutine and manage its event loop lifecycle in Python 3.7+? A asyncio.execute(coroutine()) B asyncio.start(coroutine()) C asyncio.run(coroutine()) D coroutine().start()
View answer & explanationFull Screen Mode →
43 What is the primary role of the 'Event Loop' in 'asyncio'? A Distributing threads across physical CPU sockets. B Managing and distributing the execution of asynchronous tasks, callbacks, and network I/O events cooperatively on a single thread. C Listening for mouse click events on the screen. D Monitoring operating system memory paging.
View answer & explanationFull Screen Mode →
44 What is a 'Coroutine' in Python's 'asyncio' framework? A A specialized function declared with 'async def' whose execution can be paused at 'await' points to yield control back to the event loop. B A thread created by the operating system kernel. C A generator that can only yield integers. D A compiled C extension module.
View answer & explanationFull Screen Mode →
45 What is the difference between 'threading.Lock' and 'threading.RLock'? A 'RLock' automatically releases after 1 second. B An 'RLock' is thread-safe, while 'Lock' is not. C 'Lock' can be shared across processes, while 'RLock' cannot. D An 'RLock' (Reentrant Lock) can be acquired multiple times by the SAME thread without deadlocking, whereas a standard 'Lock' deadlocks if acquired again by the owning thread.
View answer & explanationFull Screen Mode →
46 What is a 'Daemon Thread' in Python's 'threading' module? A A thread that runs exclusively in kernel space. B A thread that has higher execution priority than normal threads. C A background thread that does not prevent the Python program from exiting; when all non-daemon threads terminate, daemon threads are killed immediately. D A thread that cannot be stopped.
View answer & explanationFull Screen Mode →
47 Which module in Python standard library bypasses the GIL by spawning separate OS processes, each with its own Python interpreter and memory space? A threading B multiprocessing C asyncio D concurrent.threads
View answer & explanationFull Screen Mode →
48 Why does multi-threaded execution of CPU-bound tasks in standard CPython often run SLOWER than single-threaded execution? A Threads compete for the GIL on multiple CPU cores, causing heavy context switching, lock acquisition overhead, and cache trashing without parallelism. B Threads divide CPU frequency among themselves. C Python deletes thread variables every 5 milliseconds. D The compiler turns off code optimization in multithreaded mode.
View answer & explanationFull Screen Mode →
49 For which type of workloads does Python's 'threading' module provide genuine concurrent performance speedup despite the GIL? A 3D graphics rendering in pure Python loops B CPU-bound tasks (heavy matrix math, image processing) C Cryptographic hashing on multi-core CPUs D I/O-bound tasks (network requests, file reads/writes, database queries)
View answer & explanationFull Screen Mode →
50 What is the Global Interpreter Lock (GIL) in CPython? A A lock that serializes all database queries. B A security lock preventing unauthorized script execution. C A mutual-exclusion lock (mutex) that prevents multiple native OS threads from executing Python bytecodes simultaneously in CPython. D A hardware mechanism built into Intel CPUs for Python.
View answer & explanationFull Screen Mode →