Python

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.

Question 1
Interview Beginner
Question

What is a function in Python?

Answer:

A function is a reusable block of code that performs a specific task.

Question 2
Interview Beginner
Question

What is a module in Python?

Answer:

A module is a file containing Python code that can be imported.

Question 3
Interview Beginner
Question

What is difference between module and package?

Answer:

A module is a single file, while a package is a collection of modules.

Question 4
Interview Beginner
Question

What are arguments in functions?

Answer:

Arguments are values passed to a function.

Question 5
Interview Beginner
Question

What is return statement?

Answer:

return is used to send result back from a function.

Question 6
Interview Beginner
Question

What are *args and **kwargs?

Answer:

*args passes variable positional arguments and **kwargs passes keyword arguments.

Question 7
Interview Beginner
Question

What is lambda function?

Answer:

A lambda function is an anonymous one-line function.

Question 8
Interview Intermediate
Question

What is scope in Python?

Answer:

Scope defines the visibility of variables (local, global, enclosing, built-in).

Question 9
Interview Intermediate
Question

What is recursion?

Answer:

A function calling itself to solve smaller subproblems.

Question 10
Interview Intermediate
Question

What is import statement?

Answer:

import is used to include modules in Python code.

Question 11
Interview Intermediate
Question

What is __name__ == '__main__'?

Answer:

It ensures code runs only when file is executed directly.

Question 12
Interview Intermediate
Question

What is built-in function?

Answer:

Functions provided by Python like print(), len(), type().

Question 13
Interview Intermediate
Question

What is map() function?

Answer:

map applies a function to all elements in iterable.

Question 14
Interview Intermediate
Question

What is filter() function?

Answer:

filter selects elements based on condition.

Question 15
Interview Advanced
Question

How do you stay updated on Functions & Modules changes in Python?

Answer:

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.

Question 16
Interview Advanced
Question

Which Python built-ins or stdlib modules matter most for Functions & Modules?

Answer:

Name concrete modules (collections, itertools, pathlib, typing) and how they support Functions & Modules. Prefer stdlib before third-party when it is enough.

Question 17
Interview Advanced
Question

How do mutable default arguments or late binding bite you with Functions & Modules?

Answer:

Explain the classic default-list bug and closures in loops. Show a safe pattern when Functions & Modules uses defaults or lambdas.

Question 18
Interview Advanced
Question

What testing tools would you use for Functions & Modules logic?

Answer:

pytest with fixtures, parametrize, and coverage. Mock I/O at boundaries so Functions & Modules unit tests stay deterministic.

Question 19
Interview Advanced
Question

How does typing improve Functions & Modules maintainability?

Answer:

Annotate public APIs, use mypy/pyright in CI, and prefer Protocols for duck typing. Catch Functions & Modules contract breaks before runtime.

Question 20
Interview Advanced
Question

When would you choose a generator or comprehension for Functions & Modules?

Answer:

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