Deep Python internals, design patterns and software engineering concepts!
1. What is "monkey patching" in Python?
💡 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 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?
💡 Duck typing means Python cares about whether an object has the right methods/attributes, not its actual type.
4. What is "event-driven programming"?
💡 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 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?
💡 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?
💡 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 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]))?
💡 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?
💡 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?
💡 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?
💡 Python dictionaries use hash tables, giving O(1) average time complexity for lookups.
13. What is the difference between deepcopy and shallow copy?
💡 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?
💡 @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?
💡 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?
💡 ACID properties ensure reliable database transactions: Atomicity, Consistency, Isolation, and Durability.
17. What is the SOLID principle?
💡 SOLID: Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion — five OOP design principles.
18. What does "memoization" mean?
💡 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"?
💡 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"?
💡 Dependency injection passes (injects) dependencies from outside rather than hardcoding them, improving testability and flexibility.