💻
Programming Hard

Advanced Python and Software Engineering

Deep Python internals, design patterns and software engineering concepts!

20 Questions
35s Per Question
0+ Plays
← All Programming Quizzes 📚 Study Guide for this category →
💡 Create account to save scores & earn XP
📋 View All 20 Questions & Answers

1. What is "monkey patching" in Python?

  • A. A debugging technique
  • B. Dynamically modifying a class or module at runtime ✓
  • C. A type of inheritance
  • D. A testing framework

💡 Monkey patching modifies or extends a class or module at runtime without changing its source code — often used in testing.

2. What is a "closure" in Python?

  • A. A class that is closed
  • B. A function that retains access to variables from its enclosing scope even after that scope has finished ✓
  • C. A type of exception
  • D. A module that cannot be imported

💡 A closure is a nested function that remembers variables from its enclosing scope even when the outer function has returned.

3. What is "duck typing" in Python?

  • A. A type of error handling
  • B. Checking an object's type before use
  • C. If it walks like a duck and quacks like a duck — focus on behavior not type ✓
  • D. A way to define classes

💡 Duck typing means Python cares about whether an object has the right methods/attributes, not its actual type.

4. What is "event-driven programming"?

  • A. A type of OOP
  • B. Programs that respond to events like user actions or messages ✓
  • C. A functional programming style
  • D. A type of recursion

💡 Event-driven programming executes code in response to events (clicks, messages, sensor outputs) rather than sequential flow.

5. What is a metaclass in Python?

  • A. A class that inherits from multiple parents
  • B. A class of a class — defines how classes themselves behave ✓
  • C. A type of decorator
  • D. A module-level class

💡 A metaclass is the class of a class. Just as objects are instances of classes, classes are instances of metaclasses. type is the default metaclass.

6. What does the Singleton design pattern ensure?

  • A. A class has many instances
  • B. A class has exactly one instance and provides a global access point ✓
  • C. Multiple inheritance
  • D. Thread safety

💡 The Singleton pattern ensures only one instance of a class is ever created, providing a global point of access to it.

7. What is "context manager" in Python?

  • A. A type of class
  • B. A module for managing memory
  • C. An object that defines __enter__ and __exit__ for resource management using "with" ✓
  • D. A type of decorator

💡 Context managers use __enter__ and __exit__ to manage resources like files or connections: "with open(file) as f:"

8. What is a Python generator?

  • A. A class that creates objects
  • B. A function that returns an iterator using "yield" ✓
  • C. A type of decorator
  • D. A built-in Python module

💡 A generator uses "yield" to produce values lazily one at a time, saving memory compared to returning a full list.

9. What is the output of: list(map(lambda x: x**2, [1,2,3,4]))?

  • A. [1,4,9,16] ✓
  • B. [2,4,6,8]
  • C. [1,2,3,4]
  • D. [1,8,27,64]

💡 map() applies the lambda (x²) to each element: 1²=1, 2²=4, 3²=9, 4²=16. Result: [1,4,9,16].

10. What is the output of: print(0.1 + 0.2 == 0.3) in Python?

  • A. True
  • B. Error
  • C. None
  • D. False ✓

💡 Due to floating-point precision issues, 0.1 + 0.2 = 0.30000000000000004, not exactly 0.3. Result is False.

11. What does the Observer design pattern do?

  • A. Ensures one instance of a class
  • B. Defines a one-to-many dependency so dependents are notified of state changes automatically ✓
  • C. Converts interface of a class
  • D. Separates object construction from representation

💡 The Observer pattern defines a subscription mechanism where multiple observers are notified automatically when an object's state changes.

12. What is the time complexity of dictionary lookup in Python?

  • A. O(n)
  • B. O(log n)
  • C. O(n²)
  • D. O(1) average ✓

💡 Python dictionaries use hash tables, giving O(1) average time complexity for lookups.

13. What is the difference between deepcopy and shallow copy?

  • A. No difference
  • B. Shallow copy copies nested objects; deepcopy does not
  • C. Deepcopy copies all nested objects recursively; shallow copy only copies the top-level object ✓
  • D. Deepcopy is faster

💡 Shallow copy creates a new object but references the same nested objects. Deepcopy creates completely independent copies of everything.

14. What is the difference between @classmethod and @staticmethod?

  • A. No difference
  • B. @classmethod takes cls; @staticmethod takes no implicit first argument ✓
  • C. @staticmethod takes cls; @classmethod takes no argument
  • D. @classmethod is faster

💡 @classmethod receives the class (cls) as first argument. @staticmethod receives no implicit argument — it is just a regular function in the class namespace.

15. What is the GIL in Python?

  • A. Global Import Library
  • B. A type of decorator
  • C. General Input Loop
  • D. Global Interpreter Lock — prevents multiple threads from executing Python bytecode simultaneously ✓

💡 The GIL (Global Interpreter Lock) is a mutex that allows only one thread to execute Python bytecode at a time, limiting true multi-threading.

16. What does ACID stand for in databases?

  • A. Atomicity, Consistency, Isolation, Durability ✓
  • B. Array, Class, Interface, Data
  • C. Abstraction, Complexity, Integrity, Design
  • D. Access, Control, Input, Data

💡 ACID properties ensure reliable database transactions: Atomicity, Consistency, Isolation, and Durability.

17. What is the SOLID principle?

  • A. A type of algorithm
  • B. Five design principles for maintainable OOP code ✓
  • C. A Python framework
  • D. A database design pattern

💡 SOLID: Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion — five OOP design principles.

18. What does "memoization" mean?

  • A. Deleting unused variables
  • B. Compiling code
  • C. Caching results of expensive function calls to avoid recomputation ✓
  • D. Optimizing loops

💡 Memoization stores the results of expensive function calls and returns the cached result when the same inputs occur again.

19. What is "tail call optimization"?

  • A. A type of recursion
  • B. Optimizing recursive calls where the recursive call is the last operation, reusing stack frames ✓
  • C. A sorting technique
  • D. A memory management technique

💡 TCO reuses the current function's stack frame for the recursive call when it is the last operation, preventing stack overflow.

20. What is "dependency injection"?

  • A. A type of inheritance
  • B. Injecting malicious code
  • C. A design pattern where dependencies are passed to a class rather than created inside it ✓
  • D. A debugging technique

💡 Dependency injection passes (injects) dependencies from outside rather than hardcoding them, improving testability and flexibility.

More Programming Quizzes

View all Programming quizzes →