Q1. CPython primarily executes: A. Bytecode on a virtual machine B. Raw .py text with no bytecode C. Only LLVM bitcode D. JVM class files
Show Answer
Q2. PEP 8 is mainly about: A. Async event-loop APIs B. Style and readability conventions C. C-extension ABIs D. Package indexing
Show Answer
Q3. Which comparison tests object identity? A. <=> B. is C. == D. equals()
Show Answer
Q4. The safe way to test for None is: A. bool(x) B. x is None C. x == None D. x === null
Show Answer
Q5. Mutable default arguments are risky because: A. They are evaluated once and shared across calls B. Python forbids list defaults C. They disable GC D. They only work in classes
Show Answer
Q6. Which type is immutable? A. dict B. tuple C. set D. list
Show Answer
Q7. f-strings were introduced in: A. Python 1.5 B. Python 3.6 C. Python 2.7 D. Python 3.10 only
Show Answer
Q8. str.join(iterable) expects: A. A single bytes object B. An iterable of strings C. A file handle D. Only integers
Show Answer
Q9. dict preserves insertion order as of: A. Python 3.7+ language guarantee B. Never C. Only with OrderedDict forever D. Only in PyPy
Show Answer
Q10. set elements must be: A. Sorted B. Hashable C. Mutable lists D. Only strings
Show Answer
Q11. list.append(x) when x is a list: A. Raises TypeError B. Adds x as a single nested element C. Flattens recursively D. Extends element-wise
Show Answer
Q12. LEGB stands for: A. Local, Enclosing, Global, Built-in B. List, Enum, Generator, Bytecode C. Lock, Event, GIL, Barrier D. Lambda, Eval, Global, Bind
Show Answer
Q13. nonlocal is used to: A. Disable the GIL B. Rebind a name in an enclosing function scope C. Import C extensions D. Create a new module
Show Answer
Q14. Parameters after * in a def are: A. Deprecated B. Keyword-only C. Positional-only D. Varargs only
Show Answer
Q15. A lambda can contain: A. class bodies B. A single expression C. async with only D. Multiple statements
Show Answer
Q16. __init__ should typically: A. Return None and initialise the instance B. Return self always C. Replace __new__ D. Allocate on the stack
Show Answer
Q17. @classmethod methods receive: A. self only B. No automatic first argument C. The MRO tuple D. The class as first argument (cls)
Show Answer
Q18. super() is important because it: A. Bypasses the GIL B. Compiles to C C. Cooperates with the MRO in multiple inheritance D. Disables slots
Show Answer
Q19. @dataclass primarily generates: A. __init__/__repr__/__eq__ (and more options) B. Only async methods C. C headers D. SQL schemas
Show Answer
Q20. Catch application errors preferably with: A. except BaseException: B. except: C. except KeyboardInterrupt: only D. except Exception:
Show Answer
Q21. with open(path) as f: relies on: A. Manual f.close() only B. Daemon threads C. The context-manager protocol (__enter__/__exit__) D. PEP 8
Show Answer
Q22. A generator function contains: A. yield (and returns a generator when called) B. Only return C. goto D. malloc
Show Answer
Q23. Decorating with @dec above def f is equivalent to: A. dec = f(dec) B. f() C. import dec D. f = dec(f)
Show Answer
Q24. functools.wraps is used to: A. Speed up loops B. Create processes C. Preserve metadata of the wrapped function D. Parse JSON
Show Answer
Q25. if __name__ == "__main__": runs when: A. The file is executed as the entry script B. The file is imported as a library only C. Any function is called D. The GIL is released
Show Answer
Q26. A package is typically: A. A single .pyc only B. A thread pool C. A dict subclass D. A directory of modules (often with __init__.py)
Show Answer
Q27. The GIL means that in CPython: A. No threads exist B. Multiprocessing is impossible C. Only one thread runs Python bytecode at a time D. async is banned
Show Answer
Q28. Best fit for many concurrent sockets in one process: A. asyncio B. Only busy-spin loops C. Only raw fork bombs D. sys.setrecursionlimit
Show Answer
Q29. CPU-bound pure-Python work often uses: A. threading alone for speedups B. time.sleep C. str.split D. multiprocessing (or native code releasing the GIL)
Show Answer
Q30. queue.Queue is primarily: A. Process-only B. A GUI widget C. A thread-safe producer-consumer queue D. Immutable
Show Answer
Q31. print(bool([]), bool([0])) outputs: A. False False B. True True C. True False D. False True
Show Answer
Q32. After x = (i for i in range(3)); list(x); list(x) the second list is: A. [] B. [0, 1, 2] C. [3, 4, 5] D. Error always
Show Answer
Q33. 0.1 + 0.2 == 0.3 evaluates to: A. True B. None C. False D. SyntaxError
Show Answer
Q34. What does [*a, *b] do (3.5+)? A. Bitwise OR B. Start two threads C. Deep-copy only D. Unpack and concatenate iterables into a list
Show Answer
Q35. hashable objects can be: A. dict keys and set members B. list elements only C. Only floats D. Never compared
Show Answer
Q36. copy.copy on a nested list is: A. A deep copy of all levels B. Forbidden C. A shallow copy (nested mutables shared) D. Always identical to deepcopy
Show Answer
Q37. zip(a, b, strict=True) in 3.10+: A. Ignores length B. Sorts inputs C. Requires asyncio D. Errors if iterables have unequal lengths
Show Answer
Q38. Property decorator provides: A. Managed attribute access via methods B. Only classmethod binding C. Process forks D. Bytecode encryption
Show Answer
Q39. ABC + @abstractmethod forces: A. Faster imports B. GIL removal C. Concrete subclasses to implement the method D. JSON schema
Show Answer
Q40. raise New from original sets: A. Only __traceback__ to None B. __cause__ (explicit chaining) C. sys.path D. The MRO
Show Answer
Q41. assert is inappropriate for: A. Internal debug invariants B. Documenting assumptions in tests C. Local sanity checks with -O awareness D. Validating untrusted external input in production
Show Answer
Q42. yield from subgen: A. Only works with lists B. Starts multiprocessing C. Delegates iteration to another iterable/generator D. Disables caching
Show Answer
Q43. sys.modules caches: A. Already-imported modules B. Only pip metadata C. Thread locals only D. Open file descriptors
Show Answer
Q44. ThreadPoolExecutor belongs to: A. asyncio only B. PEP 8 C. email.mime D. concurrent.futures
Show Answer
Q45. Which creates a new thread of execution? A. t.run() B. t.join() C. t.start() D. t.is_alive() alone
Show Answer
Q46. bytes vs str in Python 3: A. str is text; bytes is raw 0–255 data B. They are interchangeable always C. bytes is always UTF-32 text D. str cannot be encoded
Show Answer
Q47. sorted(xs, key=len) returns: A. None and sorts in place B. A generator only C. A set D. A new sorted list
Show Answer
Q48. True, 1, and 1.0 as dict keys: A. Occupy three slots B. Are illegal C. Collide as equal hashes/values so last write wins D. Require OrderedDict
Show Answer
Q49. venv is used to: A. JIT-compile Python B. Replace the GIL C. Format code like black D. Isolate project dependencies from the system Python
Show Answer
Q50. Interview-safe duck typing means: A. Behaviour/interface matters more than concrete type B. Nominal inheritance only C. Only ducks as mascots D. Static typing is banned
Show Answer