All 57 questions
What are decorators in Python?
Asked in 17 of 281 interviews · last asked Oct 17 · Concept · Junior
Show answer
A decorator is a callable that takes a function and usually returns a replacement function that adds behavior. It lets you add behavior without changing the original function’s code. Common uses include logging, access checks, and caching; decorators can also apply to classes.
- `@decorate` above a function means `function = decorate(function)`.
- A wrapper can run code before or after calling the original function.
- `functools.wraps` preserves details such as the original function’s name and docstring.
Pythonfrom functools import wraps def log_call(func): @wraps(func) def wrapper(*args, **kwargs): print("Calling", func.__name__) return func(*args, **kwargs) return wrapper @log_call def greet(name): return f"Hello, {name}"What the interviewer checks: The interviewer checks whether you understand how decorators wrap functions and how to define and apply them.
Common mistake (in 5 of 11 reviewed answers): Many answers forget that explaining decorators should include defining one and applying it with @ syntax.
Other ways it was asked
- “What is a decorator in Python?”
- “What are Python decorators, and when would you use them?”
- “What is a decorator in Python, and what is it used for?”
What is a lambda function in Python, and how do you use it?
Asked in 9 of 281 interviews · last asked Oct 22 · Concept · Junior
Show answer
A lambda function is a small, anonymous function created with `lambda arguments: expression`. It returns the value of that single expression. Use it for short inline functions, such as a sorting key; use `def` when the function needs statements or clearer, reusable logic.
- A lambda can take multiple arguments, but its body must be one expression.
- The expression's value is returned automatically, without a return statement.
- Pass a lambda to sorted, map, or filter for a short operation.
Pythonpeople = [("Ana", 30), ("Ben", 20)] by_age = sorted(people, key=lambda person: person[1]) print(by_age) # [('Ben', 20), ('Ana', 30)]What the interviewer checks: The interviewer is checking whether you understand lambda syntax, its limits, and when it is useful.
Common mistake (in 4 of 9 reviewed answers): Many answers forget that a lambda is useful for passing a short inline function to tools such as sorted.
Other ways it was asked
- “What is a lambda function?”
- “What are lambda functions in Python?”
- “What are Python lambda functions, and when would you use them?”
What are Python generators, and why would you use them instead of building lists?
Asked in 6 of 281 interviews · last asked Oct 22 · Concept · Junior
Show answer
Python generators are iterators that produce values one at a time, instead of building a whole list. A generator function uses `yield` to pause and later resume with its state saved. I use generators to save memory and process large or infinite sequences when I do not need indexing or repeated passes.
- Values are produced on demand, so unused values need not be computed.
- Generators avoid storing all results at once.
- An exhausted generator cannot restart; create a new one for another pass.
- Lists support indexing and repeated passes; generators do not support indexing.
Pythondef squares(count): for number in range(count): yield number * number values = squares(3) print(next(values)) # 0 print(list(values)) # [1, 4]: only remaining values print(list(values)) # []: exhaustedWhat the interviewer checks: The interviewer is checking whether you understand lazy iteration, memory savings, and when a list is more useful.
Other ways it was asked
- “What are the advantages of generators in Python?”
- “What is a generator in Python?”
- “What are generators in Python?”
What are *args and **kwargs in Python?
Asked in 3 of 281 interviews · last asked Sep 11 · Concept · Junior
Other ways it was asked
- “What are `args` and `kwargs`?”
- “What are *args and **kwargs used for when defining a Python function?”
What is a common pitfall when using mutable default arguments in Python?
Asked in 3 of 281 interviews · last asked Oct 15 · Concept · Mid-level
Other ways it was asked
- “How do Python's mutable default arguments behave in function definitions, and how do you avoid the common pitfall?”
- “What happens when a mutable object is used as a default argument in a Python function?”
What is list comprehension?
Asked in 3 of 281 interviews · last asked Sep 18 · Concept · Junior
Other ways it was asked
- “What is list comprehension in Python?”
What is the difference between an iterator and a generator in Python?
Asked in 2 of 281 interviews · last asked Oct 10 · Concept · Mid-level
Other ways it was asked
- “In Python 3, what is the practical difference between an iterator and a generator, and how does yield change a function's behavior?”
What are the different types of arguments in Python?
Asked in 2 of 281 interviews · last asked Oct 7 · Concept · Junior
Other ways it was asked
- “What are the different types of arguments in Python, such as keyword arguments?”
What is a namespace in Python?
Asked in 2 of 281 interviews · last asked Jul 16 · Concept · Junior
Other ways it was asked
- “Can you please explain what a namespace is in Python?”
What is the LEGB rule in Python?
Asked in 2 of 281 interviews · last asked Oct 22 · Concept · Junior
Other ways it was asked
- “Can you explain the LEGB rule in Python with a code example?”
What are functions in Python, and when would you use them?
Asked in 2 of 281 interviews · last asked Oct 3 · Concept · Junior
Other ways it was asked
- “How do you create or use functions in Python?”
Can we pass a function as an argument in Python?
Asked in 2 of 281 interviews · last asked Sep 18 · Concept · Junior
Other ways it was asked
- “Can you pass a class as an argument to a function in Python?”
How can you use a Python decorator to handle exceptions across multiple functions instead of adding try/except blocks to each one?
Asked once · last asked Jul 16 · Concept · Mid-level
Other ways it was asked
- “How can a Python decorator handle exceptions raised by methods?”
What does a Python function return when it has no explicit return statement?
Asked once · last asked Oct 13 · Concept · Junior
Other ways it was asked
- “What value is assigned when you store the result of a Python function with no explicit `return` statement in a variable?”
- “What value is assigned when you store the result of a Python function with no explicit `return` statement in a variable, and does the code raise an error?”
- “What does a Python function return if it reaches the end without an explicit `return` statement?”
How would you create a decorator for a function that adds a and b, prints a message before execution, and then prints the execution time and result?
Asked once · last asked Feb 23 · Write code · Mid-level
What are the main benefits of using generators?
Asked once · last asked Jul 16 · Concept · Mid-level
Can you define decorators and generators, and when would you use each?
Asked once · last asked Jul 17 · Concept · Mid-level
How would you process 10 million items and apply a function to each using a generator?
Asked once · last asked Aug 13 · Write code · Mid-level
Write a simple decorator function that demonstrates closures and generators.
Asked once · last asked Aug 21 · Write code · Mid-level
What is the difference between map, filter, and list comprehensions?
Asked once · last asked Sep 11 · Concept · Junior
What happens if the coin and result lists are different sizes when you use a dictionary comprehension with zip?
Asked once · last asked Sep 15 · Concept · Junior
Can you write a Python decorator that authenticates a user?
Asked once · last asked Sep 24 · Write code · Mid-level
What types of Python comprehensions are available besides list and dictionary comprehensions?
Asked once · last asked Sep 29 · Concept · Junior
What does lazy evaluation mean when working with Python generators?
Asked once · last asked Sep 29 · Concept · Mid-level
What happens when mutable arguments are passed to a Python function, and why can the results differ across calls?
Asked once · last asked Sep 29 · Concept · Mid-level
How can you ensure a Python function gets a new empty dictionary each time it is called?
Asked once · last asked Sep 29 · Scenario · Mid-level
How do you define a function in Python, and how do default arguments differ from keyword arguments?
Asked once · last asked Oct 3 · Concept · Junior
Explain list comprehensions, map, filter, and reduce.
Asked once · last asked Oct 7 · Concept · Mid-level
What is the difference between return and yield?
Asked once · last asked Oct 7 · Concept · Mid-level
What are decorators, and what is a real-world use case for them?
Asked once · last asked Oct 14 · Concept · Mid-level
Other ways it was asked
- “What are decorators, and give me a real-world use case.”
What is the difference between a generator and a regular function that returns a list?
Asked once · last asked Oct 15 · Concept · Mid-level
In what situation would you implement a custom Python decorator, and why?
Asked once · last asked Oct 22 · Behavioral · Mid-level
Other ways it was asked
- “Tell me about a situation where you implemented a custom Python decorator and why you used one.”
What kinds of functionality would you wrap with a decorator?
Asked once · last asked Feb 23 · Concept · Junior
Can Python functions behave differently based on the number of arguments, as with method overloading?
Asked once · last asked Feb 23 · Concept · Junior
What are iterators in Python?
Asked once · last asked Feb 23 · Concept · Junior
Why would you define a function in Python instead of writing the code directly?
Asked once · last asked Feb 24 · Concept · Junior
Can a Python function have an empty parameter list, and how is that written?
Asked once · last asked Feb 24 · Concept · Junior
If a Python function does not explicitly return a value, does calling it produce random data from memory?
Asked once · last asked Feb 24 · Concept · Junior
How do you call a function and use its return value?
Asked once · last asked Apr 15 · Write code · Junior
What is the difference between assigning a function's return value and printing it, and why might a function call produce an empty dictionary?
Asked once · last asked Apr 15 · Scenario · Junior
Can you please explain what scope is in Python?
Asked once · last asked Jul 16 · Concept · Junior
What are Python list comprehensions, and when would you use them?
Asked once · last asked Jul 16 · Concept · Junior
Can a Python decorator pass a class to a function?
Asked once · last asked Jul 16 · Concept · Mid-level
Can you tell me about function chaining?
Asked once · last asked Jul 13 · Concept · Junior
What is the difference between list comprehension and generator expression in Python?
Asked once · last asked Jul 20 · Concept · Junior
Can you write a list comprehension that extracts only the positive elements from a list containing numbers from 0 to 10 and a few negative numbers?
Asked once · last asked Aug 11 · Write code · Junior
What is an example of a situation where you would use a Python generator?
Asked once · last asked Aug 13 · Concept · Junior
In what kind of cases do we use keyword arguments?
Asked once · last asked Aug 26 · Concept · Junior
What is a generator?
Asked once · last asked Sep 11 · Concept · Junior
What syntax do you use to define a function in Python?
Asked once · last asked Sep 17 · Concept · Junior
Why do we use lambda expressions?
Asked once · last asked Sep 18 · Concept · Junior
What is a comprehension in Python?
Asked once · last asked Sep 29 · Concept · Junior
Can you give me one use case where you would use a lambda function?
Asked once · last asked Oct 7 · Scenario · Junior
What does the `return` statement do in Python?
Asked once · last asked Oct 13 · Concept · Junior
Explain generators and the yield keyword.
Asked once · last asked Oct 14 · Concept · Junior
What are list comprehensions, and how are they different from traditional for loops?
Asked once · last asked Oct 17 · Concept · Junior
What is a docstring in Python?
Asked once · last asked Oct 18 · Concept · Junior
More Python interview questions
- All Python interview questions
- Python Basics Interview Questions
- Python Data Structures and Coding Interview Questions
- Python Files, Exceptions and Modules Interview Questions
- Python Data Engineering and Machine Learning Interview Questions
- Python APIs, Web Frameworks and Deployment Interview Questions
How this list is made
Every question here was asked by a real interviewer in a real job interview that a candidate ran MeetAssist in. After the call, the interviewer's questions are pulled from the transcript. Practice sessions, tests, exams and anything that was not a job interview are dropped.
Questions are rewritten so they make sense on their own: names of people, employers and clients are removed, and speech-to-text mistakes are fixed. Small talk, logistics and questions about one candidate's own résumé are left out. Rephrasings of the same question are merged, and the count is the number of different interviews it came up in.
The interviews come from candidates who use MeetAssist, so they lean towards software, data and AI roles: the shares describe these interviews, not every Python interview. Answers to the most asked questions are written and checked by an editor; a "common mistake" is shown only when reviews of real answers in these interviews show it, with the count.
281 interviews, 199 candidates, Nov 2025 to Oct 2026. Updated every month with new interviews.
Or add the Chrome extension