3 - Functions, Comprehensions, and Functional Patterns — Topics & Learning Outcomes

📋 Module Topics🎯 Student Learning Outcomes

Module Topics

Defining Functions

Introduces the syntax and mechanics of creating reusable functions in Python. Covers the def keyword, naming conventions, and the role of the return statement.

Parameters and Arguments

Explores the different ways values can be passed into functions, including positional, keyword, and default parameters. Establishes clear terminology between parameters and arguments.

Variable-Length Arguments: *args and **kwargs

Covers the special *args and **kwargs syntax that allows functions to accept an arbitrary number of positional or keyword arguments. Explains how these mechanisms support flexible and reusable API design.

Scope and Variable Visibility

Explains how Python resolves variable names using the LEGB rule and how the global and nonlocal keywords allow functions to modify variables in enclosing scopes.

Recursion

Introduces recursion as a technique where a function calls itself to solve a problem by reducing it to smaller instances. Covers base cases, recursive cases, and practical considerations like stack depth.

Comprehensions

Teaches the concise comprehension syntax for building lists, dictionaries, and sets from iterables. Covers optional filtering conditions and nested comprehensions.

Lambda Functions and Functional Patterns

Introduces anonymous lambda functions and the map and filter built-ins as tools for applying functional programming patterns in Python. Explains when to use these tools versus comprehensions or named functions.

Student Learning Outcomes

By the end of this module, students will be able to:

MO1
Construct Python functions using the def keyword, appropriate parameter types (positional, keyword, default, *args, and **kwargs), and explicit return statements to produce reusable, documented code
Level: ApplyType: CognitiveCourse mapping: CO2
MO2
Trace Python's LEGB scope rule to predict which value a variable name resolves to within nested and global function contexts
Level: AnalyzeType: CognitiveCourse mapping: CO2
MO3
Implement a recursive function by identifying the base case and recursive case for a given problem
Level: ApplyType: CognitiveCourse mapping: CO2
MO4
Produce list, dictionary, and set comprehensions — including filter clauses and nested iteration — to transform data from existing iterables
Level: ApplyType: CognitiveCourse mapping: CO1
MO5
Evaluate when to apply lambda functions, map(), or filter() versus comprehensions for a given data-transformation task based on readability and functional requirements
Level: EvaluateType: CognitiveCourse mapping: CO3

Course Outcomes (reference)

CO1Use variables, arrays and object structures appropriate to solve engineering problems.
CO2Write computer functions to meet specific calculation needs.
CO3Write computer programs to solve mathematical expressions and engineering problems