Free Online Flashcard Deck

5 Functions and Modular Programming Free Online FlashCards

Study 5 Functions and Modular Programming with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

What is a Python function?

Back

A function is a named, reusable block of code that performs a specific task. It helps divide large problems, reduce repetition, and improve readability, testing, and maintenance.

02
Front

What is the difference between defining and calling a function?

Back

The `def` statement defines a function and creates its function object; the function call, such as `greet()`, executes its indented body.

03
Front

How does a parameter differ from an argument?

Back

A parameter is the name listed in a function definition; an argument is the value supplied to that parameter in a function call.

04
Front

How do positional and keyword arguments differ?

Back

Positional arguments are matched by order, while keyword arguments are matched by parameter name. Positional arguments must come before keyword arguments.

05
Front

When does Python use a default parameter value?

Back

A default parameter value is used when the caller omits that argument. The default is evaluated when the function is defined, not on each call.

06
Front

What do `*args` and `**kwargs` collect?

Back

`*args` collects extra positional arguments into a tuple, while `**kwargs` collects extra keyword arguments into a dictionary.

07
Front

What does `return` do?

Back

`return` sends a value to the caller and immediately ends that function call. Unlike `print()`, it makes the result available for further computation.

08
Front

What does a function return without `return`?

Back

If execution reaches the end without a `return` statement, Python returns `None`. Printing a value does not automatically return it.

09
Front

What does the LEGB rule describe?

Back

LEGB is Python’s name-resolution order: Local, Enclosing, Global, then Built-in scope.

10
Front

What does assignment inside a function usually create?

Back

An assignment inside a function normally creates or updates a local variable, even when a module-level variable has the same name.

11
Front

What is a function docstring?

Back

A docstring is a string literal placed first in a function body. Python stores it in the function’s `__doc__` attribute for documentation tools and users.

12
Front

What is modular problem-solving?

Back

Modular problem-solving divides a program into focused components, designs their interfaces, tests them independently, composes them, and then refactors the result.