Python Interview Q&A
Covers data types, comprehensions, OOP, lambda functions, decorators, args/kwargs, generators, and more.
Source: GOLDEN_QUESTIONNAIRE_JULY_2026.pdf • Answers are hidden — click a question to reveal its full interview answer. Use bookmarks + Mark as Complete to track prep.
List vs Tuple vs Set vs Dictionary
click to reveal answerInterview Answer: List, Tuple, Set, and Dictionary are the four built-in collection data types in Python. Lists are mutable and ordered, whereas tuples are immutable and ordered. Sets store only unique elements and provide very fast membership testing, while dictionaries store data as key-value pairs for efficient lookups. In my projects, I use lists for collections of records, tuples for fixed values, sets for removing duplicates, and dictionaries for mapping or lookup operations.
What is List Comprehension and Dictionary Comprehension?
click to reveal answerInterview Answer: List comprehension and dictionary comprehension provide a concise way to create lists and dictionaries in a single line of code. They improve readability and are generally faster than traditional loops. List comprehension returns a list, while dictionary comprehension returns key-value pairs. I often use them for quick data transformations and filtering.
What is Inheritance and its types?
click to reveal answerInterview Answer: Inheritance is an OOP concept that allows one class to inherit properties and methods from another class, promoting code reusability. Python supports Single, Multiple, Multilevel, Hierarchical, and Hybrid inheritance. It helps reduce code duplication and makes applications easier to maintain. In real projects, I use inheritance to create specialized classes from common base classes.
What is a Lambda Function?
click to reveal answerInterview Answer: A lambda function is an anonymous, single-line function used for simple operations without defining a regular function. It is commonly used with functions like map(), filter(), and reduce(). Lambda functions make the code shorter and more readable for small transformations. I use them mainly for lightweight data processing tasks.
What are Decorators?
click to reveal answerInterview Answer: Decorators are functions that extend or modify the behavior of another function without changing its source code. They are implemented using the @ symbol. Decorators are commonly used for logging, authentication, caching, and execution time measurement. In data engineering projects, decorators are useful for logging ETL job execution.
What is Shallow Copy vs Deep Copy?
click to reveal answerInterview Answer: A shallow copy creates a new object but shares references to nested objects, so changes in nested elements affect both copies. A deep copy creates a completely independent copy of both the object and all nested objects. Python provides copy() for shallow copy and deepcopy() for deep copy. I use deep copy when working with nested data structures to avoid unintended modifications.
What are *args and **kwargs?
click to reveal answerInterview Answer: *args allows a function to accept any number of positional arguments, while **kwargs allows any number of keyword arguments. Internally, *args is stored as a tuple and **kwargs as a dictionary. They make functions flexible and reusable. I use them when the number of input parameters is unknown.
What is a Constructor? Explain __init__()
click to reveal answerInterview Answer: A constructor is a special method that is automatically called when an object is created. In Python, the constructor is the __init__() method. It is mainly used to initialize object attributes with default or user-provided values. This ensures every object starts with the required initial state.
What are Generators?
click to reveal answerInterview Answer: Generators are functions that produce values one at a time using the yield keyword instead of returning all values at once. They are memory efficient because they generate values only when needed. This makes them ideal for processing large files or streaming data. In data engineering, generators are useful for handling large datasets without consuming excessive memory.
What are the OOP Concepts?
click to reveal answerInterview Answer: The four main OOP concepts are Encapsulation, Abstraction, Inheritance, and Polymorphism. Encapsulation protects data by restricting direct access, abstraction hides implementation details, inheritance enables code reuse, and polymorphism allows the same interface to have multiple implementations. These principles make code modular, reusable, and maintainable.
What is Multi-threading vs Multi-processing?
click to reveal answerInterview Answer: Multithreading executes multiple threads within the same process and is best suited for I/O-bound tasks like API calls and file operations. Multiprocessing creates separate processes with independent memory and is ideal for CPU-intensive tasks. Unlike multithreading, multiprocessing is not limited by Python's GIL. I choose the approach based on the workload.
Do you know how Garbage Collection works in Python?
click to reveal answerInterview Answer: Yes. Python automatically manages memory using reference counting and a garbage collector. When an object's reference count becomes zero, its memory is released immediately. Python also detects and removes circular references using the gc module. This automatic memory management helps prevent memory leaks and improves application performance.