16.What is the difference between append() and extend() in lists?
Ans. append() adds a single element to the end of a list, whereas extend() iterates over its argument and adds each item to the list.
17.What are list comprehensions?
Ans. A concise syntax to construct new lists from existing iterables based on evaluated conditions: [x for x in iterable if condition].
18.How does lambda work in Python?
Ans. Lambda expressions create small, inline, anonymous functions with the syntax lambda arguments: expression.
19.What is the difference between deep copy and shallow copy?
Ans. Shallow copy constructs a new object populated with references to the original nested elements. Deep copy recursively creates new copies of all nested objects.
20.Explain generator functions and the yield keyword.
Ans. Generators use yield to return data lazily one item at a time, pausing function execution state between calls to optimize memory.
21.What are *args and **kwargs?
Ans. *args accepts a variable number of non-keyword positional arguments as a tuple, while **kwargs accepts variable keyword arguments as a dictionary.
22.What is the Global Interpreter Lock (GIL)?
Ans. GIL is a mutex that prevents multiple native threads from executing Python bytecodes simultaneously within a single process.
23.What are list comprehensions vs generator expressions?
Ans. List comprehensions store the entire list in memory, whereas generator expressions produce items dynamically on demand.
24.How do you perform file handling in Python?
Ans. By using the built-in open() function alongside context managers (with open(...) as file:), ensuring automatic file closure.
25.What is method resolution order (MRO)?
Ans. MRO defines the order in which Python searches parent classes when resolving methods in multiple inheritance scenarios.
26.How do you implement inheritance in Python?
Ans. By passing the parent class name inside parentheses when defining a child class: class ChildClass(ParentClass):.
27.What is the use of the map() function?
Ans. map(function, iterable) applies a specified function to all items in an input iterable and yields an iterator result.
28.Explain the filter() function.
Ans. filter(function, iterable) filters elements of an iterable based on whether the given function returns True or False.
29.What are dunder (magic) methods?
Ans. Special methods surrounded by double underscores (e.g., __init__, __str__) that allow classes to overload built-in operations.
30.How do you check for unique elements in a list?
Ans. Convert the list into a set: len(input_list) == len(set(input_list)).
31.What is monkey patching in Python?
Ans. Monkey patching refers to dynamically modifying a module or class attribute at runtime without altering original source files.
32.Why is python interview preparation so focused on generators?
Ans. Generators demonstrate an engineer's capability to process large datasets efficiently without overloading system RAM.
33.Explain the zip() function.
Ans. zip() aggregates elements from multiple iterables into tuples and returns an iterator of those combined pairs.
34.How do you handle assertions in Python?
Ans. Using the assert keyword to test internal code assumptions; if the expression evaluates to False, an AssertionError is raised.
35.What are abstract base classes (ABCs)?
Ans. ABCs define common interfaces for a set of subclasses without providing full concrete method implementations.