Functions & Modules Interview Questions
Functions, lambda, *args/**kwargs, scope, imports, and built-in higher-order functions.
- 20Questions with answers
- 3Difficulty levels
Questions (20)
Browse beginner, intermediate, and advanced questions with answers — hide them when you want to self-test.
What is a function in Python?
A function is a reusable block of code that performs a specific task.
What is a module in Python?
A module is a file containing Python code that can be imported.
What is difference between module and package?
A module is a single file, while a package is a collection of modules.
What are arguments in functions?
Arguments are values passed to a function.
What is return statement?
return is used to send result back from a function.
What are *args and **kwargs?
*args passes variable positional arguments and **kwargs passes keyword arguments.
What is lambda function?
A lambda function is an anonymous one-line function.
What is scope in Python?
Scope defines the visibility of variables (local, global, enclosing, built-in).
What is recursion?
A function calling itself to solve smaller subproblems.
What is import statement?
import is used to include modules in Python code.
What is __name__ == '__main__'?
It ensures code runs only when file is executed directly.
What is built-in function?
Functions provided by Python like print(), len(), type().
What is map() function?
map applies a function to all elements in iterable.
What is filter() function?
filter selects elements based on condition.
How do you stay updated on Functions & Modules changes in Python?
Follow release notes, RFCs or PEPs, official blogs, and reputable courses. Experiment in side projects when new Functions & Modules-related features ship so you can speak confidently about migration paths.
Which Python built-ins or stdlib modules matter most for Functions & Modules?
Name concrete modules (collections, itertools, pathlib, typing) and how they support Functions & Modules. Prefer stdlib before third-party when it is enough.
How do mutable default arguments or late binding bite you with Functions & Modules?
Explain the classic default-list bug and closures in loops. Show a safe pattern when Functions & Modules uses defaults or lambdas.
What testing tools would you use for Functions & Modules logic?
pytest with fixtures, parametrize, and coverage. Mock I/O at boundaries so Functions & Modules unit tests stay deterministic.
How does typing improve Functions & Modules maintainability?
Annotate public APIs, use mypy/pyright in CI, and prefer Protocols for duck typing. Catch Functions & Modules contract breaks before runtime.
When would you choose a generator or comprehension for Functions & Modules?
Generators save memory for large streams; comprehensions are clear for small transforms. Justify the choice for Functions & Modules data sizes.
Practice with AI mock interviews
Run Python mock interviews with AI follow-ups, instant feedback, and analytics on AiLx.
Free to start · No credit card required