By the end of this module you can do everything below. The objectives and their wording come from the official PCEP-30-03 syllabus.
4.1.1 Define and invoke user-defined functions
- Explain how functions support code decomposition, reuse, and maintainability.
- Define a function using the
defkeyword. - Create valid function names according to Python naming rules.
- Define a function body using correct indentation.
- Invoke a user-defined function.
- Trace the order in which function definitions and function calls are executed.
4.1.2 Return values from functions
- Use the
returnstatement to return a result from a function. - Assign a returned value to a variable.
- Use returned values in expressions and function calls.
- Explain the difference between returning a value and displaying a value with
print(). - Explain how
returnterminates the current function call. - Return multiple values from a function.
- Recognize when a function implicitly returns
None. - Use the
Nonevalue to represent the absence of a meaningful result.
4.1.3 Define parameters and pass arguments to functions
- Distinguish between parameters in function definitions and arguments in function calls.
- Pass arguments by position and keyword, and combine them in the correct order.
- Define parameters with default values.
- Call functions using default values or override them with explicit arguments.
- Use keyword arguments with built-in functions such as
print(), includingsepandend. - Recognize invalid function calls caused by missing, duplicated, or incorrectly ordered arguments.