Python Interview Questions – Part 3
━━━━━━━━━━━━━━━━━━━━━━
01. What is a Decorator in Python?
A decorator is a function that modifies or extends another function's behavior without changing its original source code.
Key Points
- Uses the
- Supports reusable functionality
- Commonly used for logging and access control
02. What is a Generator in Python?
A generator produces values one at a time instead of storing the entire sequence in memory.
Key Points
- Commonly uses the
- Generates values lazily
- Useful for processing large datasets
03. What is an Iterator in Python?
An iterator is an object that returns values one at a time using the
Key Points
- Supports the iterator protocol
- Works with
- Raises
04. What is the Use of the yield Keyword?
The
Key Points
- Produces values lazily
- Preserves local state between yields
- Helps reduce memory usage for large sequences
05. What is the Difference Between Shallow Copy and Deep Copy?
A shallow copy creates a new outer object but keeps references to nested objects. A deep copy recursively copies nested objects as well.
Key Points
- Shallow copy may share nested objects
- Deep copy duplicates nested structures
- Python provides
━━━━━━━━━━━━━━━━━━━━━━
UPDATEGADH | Technology Tutorials & Interview Questions
#Python #PythonInterviewQuestions #PythonProgramming #CodingInterview #PythonDevelopers #Programming #UPDATEGADH
━━━━━━━━━━━━━━━━━━━━━━
01. What is a Decorator in Python?
A decorator is a function that modifies or extends another function's behavior without changing its original source code.
Key Points
- Uses the
@decorator syntax- Supports reusable functionality
- Commonly used for logging and access control
02. What is a Generator in Python?
A generator produces values one at a time instead of storing the entire sequence in memory.
Key Points
- Commonly uses the
yield keyword- Generates values lazily
- Useful for processing large datasets
03. What is an Iterator in Python?
An iterator is an object that returns values one at a time using the
__next__() method until the sequence is exhausted.Key Points
- Supports the iterator protocol
- Works with
iter() and next()- Raises
StopIteration when exhausted04. What is the Use of the yield Keyword?
The
yield keyword returns a value from a generator while preserving its execution state. Execution resumes when the next value is requested.Key Points
- Produces values lazily
- Preserves local state between yields
- Helps reduce memory usage for large sequences
05. What is the Difference Between Shallow Copy and Deep Copy?
A shallow copy creates a new outer object but keeps references to nested objects. A deep copy recursively copies nested objects as well.
Key Points
- Shallow copy may share nested objects
- Deep copy duplicates nested structures
- Python provides
copy.copy() and copy.deepcopy()━━━━━━━━━━━━━━━━━━━━━━
UPDATEGADH | Technology Tutorials & Interview Questions
#Python #PythonInterviewQuestions #PythonProgramming #CodingInterview #PythonDevelopers #Programming #UPDATEGADH