PYTHON TECHNICAL INTERVIEW – DETAILED DEFINITIONS WITH KEYWORDS + SHORT
EXAMPLES
1. List vs Tuple
- List: Ordered, mutable, dynamic, allows duplicates. Used when frequent insert/update operations.
Example: lst = [1, 2, 3]
- Tuple: Ordered, immutable, faster than list, used for fixed data. Example: tup = (1, 2, 3)
2. Mutable vs Immutable
- Mutable: Can be modified after creation (list, dict, set). Example: [Link](4)
- Immutable: Value cannot change; new object created (int, str, tuple). Example: s = "hi"
3. == vs is
- == : Checks value equality. Example: 5 == 5
- is : Checks object identity in memory. Example: a is b
4. Shallow Copy vs Deep Copy
- Shallow: Copies object but references nested objects. Example: [Link]()
- Deep: Recursively copies everything; independent clone. Example: [Link]()
5. Class vs Object
- Class: Blueprint defining attributes/methods. Example: class Car: pass
- Object: Instance created from class. Example: c = Car()
6. Inheritance
- Child class acquires parent’s attributes/methods to promote reusability. Example: class B(A)
7. Polymorphism
- Same function name behaves differently across classes. Example: override sound()
8. Encapsulation
- Protecting internal data using private attributes; controlled access via methods. Example:
self.__balance
9. Abstraction
- Hiding complex implementation; showing essential behavior. Example: Abstract classes/interfaces
10. Constructor vs Method
- Constructor: __init__, called automatically to initialize object. Example: __init__(self)
- Method: Function inside class performing behavior. Example: def run()
11. Class Variable vs Instance Variable
- Class Variable: Shared across all objects. Example: wheels = 4
- Instance Variable: Specific to each object inside __init__. Example: [Link]
12. Method Overriding
- Child redefines parent’s method to change behavior. Example: [Link]()
13. Method Overloading
- Not supported natively; simulated using default args/*args. Example: def add(a,b=0)
14. @staticmethod vs @classmethod
- staticmethod: No self/cls, utility function inside class. Example: add()
- classmethod: Uses cls, modifies class variables. Example: change_name()
15. Recursion
- Function calling itself with base condition; uses call stack. Example: factorial()
16. List vs Array
- List: Flexible, mixed types, slower for numeric ops. Example: [1,"a"]
- Array: Same type, memory-efficient, faster numeric ops (array/NumPy)
17. Decorator
- Higher-order function modifying another function without touching its code. Example: @decorator
18. __str__ vs __repr__
- __str__: Human-readable output. Example: "Person object"
- __repr__: Developer/debug-friendly representation. Example: Person(name='A')
19. Generator
- Function using yield; returns lazy sequence, saves memory. Example: yield i
20. append() vs extend()
- append: Adds single element. Example: [Link](5)
- extend: Adds each element from iterable. Example: [Link]([1,2])
21. remove() vs pop()
- remove: Removes by value. Example: [Link](3)
- pop: Removes by index, returns value. Example: [Link]()
22. sort() vs sorted()
- sort: In-place sorting. Example: [Link]()
- sorted: Returns new sorted list. Example: sorted(lst)
23. *args vs **kwargs
- *args: Variable-length positional arguments. Example: func(1,2)
- **kwargs: Variable-length named arguments. Example: func(a=1,b=2)