Learn Without Walls
← Back to Module 9

Study Guide: Functions

Module 9 Review Materials

Key Terms

Function: A named, reusable block of code that performs a specific task. Defined with the def keyword.
Parameter: A variable listed in a function's definition that acts as a placeholder for input data.
Argument: The actual value passed to a function when it is called.
Return Value: The value a function sends back to the caller using the return statement.
None: Python's special value representing "no value." Returned by functions without a return statement.
Docstring: A documentation string placed as the first line of a function body, enclosed in triple quotes.
Default Parameter: A parameter with a pre-assigned value that is used when no argument is provided for it.
Keyword Argument: An argument passed using name=value syntax, allowing arguments to be given in any order.
*args: Syntax for collecting extra positional arguments into a tuple.
**kwargs: Syntax for collecting extra keyword arguments into a dictionary.
Scope: The region of a program where a variable is accessible. Python uses Local, Enclosing, Global, and Built-in scopes (LEGB).
Local Variable: A variable defined inside a function; only accessible within that function.
Global Variable: A variable defined outside all functions; accessible throughout the module.

Lesson 1: Defining Functions with def

Key Concepts

Lesson 2: Parameters and Return Values

Key Concepts

Lesson 3: Default and Keyword Arguments

Key Concepts

Lesson 4: Scope – Local vs Global

Key Concepts

Common Mistakes to Avoid

Review Questions

  1. What keyword defines a function? What punctuation marks the end of the function header?
  2. What is the difference between defining and calling a function?
  3. What is the difference between print() and return?
  4. What does a function return if it has no return statement?
  5. How do you return multiple values from a function?
  6. What is the difference between a parameter and an argument?
  7. What are default parameter values and why are they useful?
  8. When would you use *args? When would you use **kwargs?
  9. What is the LEGB rule? List the four scopes in order.
  10. Why should you avoid using the global keyword? What is a better alternative?
Take the Quiz Back to Module 9