🌍 Python Programming · flashcards

Python Programming Functions And Modular Programming Flashcards

50 question-and-answer cards covering Functions And Modular Programming as it is examined in Python Programming. 24 of them are printed below, taken from across the deck — no signup, no paywall on the preview.

50Cards in deck
24Free preview
~118Chars per answer
FreePrice

24 sample cards from the Functions And Modular Programming deck

Sampled from the end of the deck, so these are different cards from the ones shown on the syllabus page.

  1. What is a closure in Python?

    A closure is a nested function that remembers and accesses variables from its enclosing scope even after the outer function has finished executing.

  2. What is the syntax of a lambda function in Python?

    lambda parameters: expression — e.g., lambda x, y: x + y. It returns the value of the single expression.

  3. Name two key limitations of lambda functions compared to def functions.

    A lambda can contain only a single expression (no statements/assignments) and is anonymous (no name unless assigned). It also cannot include annotations or docstrings effectively.

  4. A common use of lambda is as the key argument to sorted(). What does the key function do?

    It returns a value for each element that sorted() uses as the sorting criterion (e.g., sorted(data, key=lambda x: x[1])).

  5. What is recursion?

    A technique where a function calls itself to solve a problem by breaking it into smaller subproblems.

  6. What two essential components must every recursive function have?

    A base case (a condition that stops the recursion) and a recursive case (the function calling itself with a modified argument moving toward the base case).

  7. What error occurs when recursion goes too deep in Python, and what is the default recursion limit?

    A RecursionError (maximum recursion depth exceeded). The default limit is 1000, adjustable via sys.setrecursionlimit().

  8. Write a recursive definition for factorial(n).

    factorial(n) = 1 if n == 0 (base case), else n * factorial(n - 1).

  9. What is tail recursion, and does CPython optimize it?

    Tail recursion is when the recursive call is the last operation in the function. CPython does NOT perform tail-call optimization, so deep tail recursion still risks stack overflow.

  10. What is a decorator in Python?

    A decorator is a callable that takes a function (or class) and returns a modified or enhanced version of it, typically applied with the @decorator syntax above a definition.

  11. The syntax @my_decorator above def func(): is equivalent to what explicit statement?

    func = my_decorator(func)

  12. Why use functools.wraps inside a decorator's wrapper function?

    It copies the original function's metadata (__name__, __doc__, etc.) to the wrapper, so the decorated function retains its identity and documentation.

  13. How do you write a decorator that accepts its own arguments?

    Use three nested levels: an outer function taking the decorator arguments, returning the actual decorator, which returns the wrapper (e.g., @repeat(3)).

  14. What is the difference between a module and a package in Python?

    A module is a single .py file containing Python code; a package is a directory containing modules (and typically an __init__.py file) that groups related modules.

  15. What are the main ways to import from a module?

    import module, import module as alias, from module import name, from module import name as alias, and from module import * (discouraged).

  16. What is the purpose of the if __name__ == '__main__': block?

    It runs code only when the file is executed directly as a script, not when it is imported as a module (where __name__ equals the module's name).

  17. What is sys.path and why does it matter for imports?

    It is a list of directory paths Python searches to find modules to import. If a module's directory is not on sys.path, the import fails.

  18. What role does __init__.py play in a package?

    It marks a directory as a (regular) package and can run initialization code or define what the package exposes. (Since Python 3.3, namespace packages can exist without it.)

  19. Which standard library module provides mathematical functions like sqrt, sin, and constants pi and e?

    The math module.

  20. Which standard library module is used to generate random numbers and make random selections?

    The random module (e.g., random.random(), random.randint(), random.choice()).

  21. Which standard library module provides functions to interact with the operating system, such as file paths and environment variables?

    The os module (with os.path for path manipulation).

  22. Which standard library module is used to work with dates and times?

    The datetime module.

  23. Which standard library module is used to encode and decode JSON data?

    The json module (json.dumps to serialize, json.loads to deserialize).

  24. What is the standard tool/format for packaging and distributing Python projects on PyPI, and what command installs packages?

    Projects are packaged as wheels/sdists (configured via pyproject.toml or setup.py) and published to PyPI; pip is the command used to install them (pip install package).

What this deck covers

This deck covers the Functions And Modular Programming portion of the Python Programming syllabus in question-and-answer form. Browse the full Python Programming syllabus to see how it fits with the rest.

Answers are written to be recallable, not just readable — averaging about 118 characters, which is long enough to carry the reasoning and short enough to say out loud.

A deck like this earns its keep on the second and third pass. Read the syllabus first so you know the shape of the subject, then use the cards to find the specific facts that have not stuck.

Functions And Modular Programming flashcards FAQ

How many Functions And Modular Programming flashcards are in this Python Programming deck?

50 cards. This page previews 24 of them, sampled evenly across the deck so you can judge the difficulty before installing anything.

Are these Python Programming flashcards free?

Yes. The preview here is free to read with no signup, and the full 50-card deck is free inside the Examius app.

What do the Functions And Modular Programming cards cover?

They follow the Functions And Modular Programming portion of the Python Programming syllabus, in question-and-answer form.

How should I use these flashcards?

Read the syllabus first so you know the shape of the subject, then drill the deck. Examius schedules each card with spaced repetition, so cards you keep missing come back sooner and ones you know drift further apart.