Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Python 10 questions

Decorators, Generators & Iterators

Understand Python advanced concepts. Learn decorator decorators, generator yield states, custom iterators, and memory-efficient iterators.

More Python
Interview questions 1–10 of 10
1

What is a decorator in Python and how does it work?

A decorator is a function that takes another function as input and returns a modified version of it, allowing...

Read answer →
2

How do you write a decorator that accepts arguments?

A decorator with arguments needs an extra layer of nesting - an outer function that takes the decorator argume...

Read answer →
3

What does functools.wraps do and why is it important in decorators?

Without functools.wraps, a decorated function loses its original name, docstring, and metadata, since the wrap...

Read answer →
4

What is a generator and how does yield work?

A generator is a function that produces a sequence of values lazily, one at a time, using yield instead of ret...

Read answer →
5

What is the iterator protocol and how do __iter__ and __next__ work?

The iterator protocol requires an object to implement __iter__ (returns the iterator itself) and __next__ (ret...

Read answer →
6

What is the difference between a generator expression and a list comprehension?

AspectList comprehensionGenerator expressionSyntax[x for x in ...](x for x in ...)EvaluationEager - computes a...

Read answer →
7

How do you chain multiple generators together, and what is yield from used for?

yield from delegates iteration to a sub-generator or iterable, simplifying the common pattern of a generator t...

Read answer →
8

What are common built-in decorators like @staticmethod, @classmethod, and @property?

DecoratorFirst parameterCalled onPurpose@staticmethodNone - no automatic self/clsClass or instanceUtility func...

Read answer →
9

How do you stack multiple decorators on a single function, and what order do they execute in?

When stacking decorators, they wrap the function from the BOTTOM up, but the wrapped calls execute from the TO...

Read answer →
10

What is the itertools module and what are some commonly used functions from it?

itertools is a standard library module providing fast, memory-efficient tools for working with iterators, cove...

Read answer →