1/32
Chapter 6 - Functions
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
What is a function in Python?
A named block of code that performs a task; created with def, called with name().
Why use functions?
Reduce repetition, improve readability, keep code organized.
What does return do?
Sends one value back to the caller and ends the function.
What happens if a function has no return?
It returns None.
What is a parameter?
Variable in the function definition.
What is an argument?
The value provided during the call.
How do multiple parameters work?
Arguments match parameters by position unless using keyword arguments.
What is a nested function call?
A function used inside another function call.
Example: int(input())
What is a void function?
A function that prints but does not return anything (None).
What is polymorphism in Python?
Operators behave differently depending on argument types.
Examples:5 + 5 → 10"a" + "b" → "ab"
What is dynamic typing?
Variable types are determined at runtime and can change.
What benefits do functions offer?
Readability
Modular development
Avoiding redundant code
Easy testing
Smaller, focused tasks
What is a function stub?
Placeholder used before writing full code.
Examples:pass or print("Not implemented").
Are functions objects?
Yes. They can be assigned to variables or passed as arguments.
What operation do functions support?
The call operation: func().
Common function mistakes?
Copy-paste errors
Returning the wrong variable
Forgetting a return (causes None)
What is local scope?
Variables created inside a function; disappear when function ends.
What is global scope?
Variables defined outside functions.
How to modify a global inside a function?
Use global varname.
How does Python find a variable name?
Local
Global
Built-in
(if not found → NameError)
How does Python pass arguments?
Pass-by-assignment (object reference).
What happens to immutable objects (int, str)?
"Changes" inside the function do not affect the original.
What about mutable objects (list, dict)?
Changes inside the function affect the original.
What are keyword arguments?
Calling parameters using their names: func(x=3, y=5).
What is a default parameter?
A parameter with a preset value if not provided.
What is the danger with mutable default args?
Same list/dict is reused across calls.
Correct pattern:
def func(a=None):
if a is None:
a = []What does *args collect?
Extra positional arguments → tuple.
What does **kwargs collect?
Extra keyword arguments → dictionary.
Ordering rule of arbitrary arguments?
normal → *args → **kwargs
How to return multiple values?
Return a tuple: return a, b
What is unpacking?
Assigning tuple elements to variables:x, y = func()
What is a docstring?
Triple-quoted description inside a function.
Purpose of docstrings?
Document behavior and be readable via help().