# Module 3: Functions, Strings & Standard Libraries

MODULE OVERVIEW

This module introduces learners to Python functions, reusable programming
structures and tools available through Python's standard libraries. It explores
how functions help organise code, simplify repetitive tasks and make programs
easier to maintain.



Learners will progress from understanding functions and creating user-defined
functions to working with arguments, variable scope, decorators, lambda
expressions, recursion and generators. The module also introduces Python's
standard library, helping learners understand how built-in modules and reusable
functionality can support different programming tasks.



These concepts help learners develop more structured, efficient and maintainable
programs that can be applied to practical business and programming scenarios.






WHAT WILL BE COVERED


1. INTRODUCTION TO FUNCTIONS

Understand how functions help break programs into smaller, organised and
reusable blocks of code.

 * Introduction to functions in Python.

 * Understanding the purpose of functions.

 * Why functions are used in programming.

 * Function structure and syntax.

 * Calling and executing functions.

 * Understanding reusable code.

 * Organising programs using functions.

Practical example: Create a reusable calculation function for computing totals,
discounts or basic operational metrics instead of writing the same calculation
repeatedly.


2. USER-DEFINED FUNCTIONS

Learn how to create custom functions to perform specific operations based on
program requirements.

 * Defining user-defined functions.

 * Using the def keyword.

 * Calling user-defined functions.

 * Returning values from functions.

 * Working with function parameters.

 * Creating reusable program logic.

 * Combining functions to structure a program.

Practical example: Create functions to calculate invoice totals, process
employee information or perform repeated calculations across different records.


3. PYTHON STANDARD LIBRARY

Explore Python's standard library and understand how built-in modules provide
ready-to-use functionality for common programming tasks.

 * Introduction to Python standard libraries.

 * Understanding modules and their purpose.

 * Importing Python modules.

 * Working with built-in functionality.

 * Using library functions.

 * Exploring reusable modules for common programming requirements.

 * Applying standard library features within Python programs.

Practical example: Use Python's available modules to support calculations, data
processing, date-related tasks and other routine programming requirements
without developing every function from scratch.


4. PYTHON ARGUMENTS

Understand how arguments are passed to functions and how functions use supplied
values to perform operations.

 * Understanding parameters and arguments.

 * Passing arguments to functions.

 * Working with positional arguments.

 * Understanding keyword arguments.

 * Working with default arguments.

 * Understanding argument behaviour.

 * Using arguments to create flexible functions.

Practical example: Create a reusable calculation function that accepts different
sales values, tax rates or discount percentages based on the inputs provided.


5. PYTHON *ARGS AND **KWARGS

Learn how Python functions can accept flexible numbers of arguments and
keyword-based inputs.

 * Understanding *args.

 * Passing multiple positional arguments.

 * Working with variable-length arguments.

 * Understanding **kwargs.

 * Passing multiple keyword arguments.

 * Handling flexible function inputs.

 * Using variable-length arguments in reusable functions.

Practical example: Develop functions that process varying numbers of values or
accept multiple named inputs, allowing the same function to support different
operational scenarios.


6. PYTHON SCOPE

Understand how variables are accessed and managed within different parts of a
Python program.

 * Introduction to variable scope.

 * Understanding local variables.

 * Understanding global variables.

 * Working with variable accessibility.

 * Understanding function-level scope.

 * Using scope in functions.

 * Understanding how scope affects program behaviour.

Practical example: Organise program variables so that calculations, temporary
values and shared information are managed appropriately across different
functions.


7. PYTHON DECORATORS

Explore decorators and understand how they can extend or modify the behaviour of
functions without directly changing the original function's code.

 * Introduction to decorators.

 * Understanding functions as objects.

 * Working with nested functions.

 * Understanding wrapper functions.

 * Applying decorators to functions.

 * Understanding how decorators modify function behaviour.

 * Exploring reusable function enhancements.

Practical example: Understand how reusable function wrappers can support
logging, timing, validation or other additional behaviour around a function.


8. PYTHON LAMBDA

Learn how lambda expressions are used to create compact, anonymous functions for
simple operations.

 * Introduction to lambda expressions.

 * Understanding anonymous functions.

 * Creating lambda functions.

 * Working with lambda expressions.

 * Using lambda with other Python functions.

 * Applying lambda expressions to simple calculations and data operations.

Practical example: Use compact functions to sort records based on a specific
value, calculate simple transformations or apply quick operations to data.


9. PYTHON RECURSION

Understand recursion and how functions can call themselves to solve problems
through repeated or smaller operations.

 * Introduction to recursion.

 * Understanding recursive functions.

 * Creating recursive functions.

 * Understanding recursive calls.

 * Identifying base conditions.

 * Understanding recursion termination.

 * Applying recursion to suitable programming problems.

Practical example: Understand how recursive logic can be used to process nested
structures, hierarchical information or problems that can be divided into
smaller steps.


10. PYTHON GENERATORS

Learn how generators provide a way to produce values incrementally rather than
storing all values at once.

 * Introduction to generators.

 * Understanding generator functions.

 * Using the yield keyword.

 * Understanding generator execution.

 * Working with generated values.

 * Understanding incremental data processing.

 * Applying generators to data-processing tasks.

Practical example: Process records or values progressively when working with
larger data sets, helping avoid loading all data into memory at once.


SKILLS YOU WILL GAIN

By completing this module, learners will develop the skills to:

 * Create and use functions in Python.

 * Develop reusable program logic.

 * Define functions with parameters and return values.

 * Work with positional, keyword and default arguments.

 * Handle flexible arguments using *args and **kwargs.

 * Use Python standard library modules.

 * Understand variable scope and manage variables within functions.

 * Apply decorators to extend function behaviour.

 * Write lambda expressions for simple operations.

 * Develop recursive functions for suitable programming problems.

 * Create generators for incremental data processing.

 * Structure Python programs into reusable and maintainable components.


LEARNING OUTCOMES

After completing this module, learners will be able to:

 * Develop reusable Python functions to automate recurring calculations and
   business tasks.

 * Create structured programs that reduce repeated coding and simplify
   maintenance.

 * Build flexible functions that can process different inputs and business
   scenarios.

 * Use Python standard libraries to support common operational and programming
   requirements.

 * Organise program logic to improve readability, maintainability and
   efficiency.

 * Develop reusable components for data processing and routine task automation.

 * Apply lambda expressions and other functional programming techniques to
   simple data operations.

 * Use generators to process information progressively where appropriate.

 * Develop a foundation for building larger Python applications, automation
   scripts and data-processing solutions.


CERTIFICATION ALIGNMENT

This module supports Python programming concepts relevant to the Python
Institute PCAP certification pathway.

Topic Covered

Certification-Relevant Knowledge

Introduction to Functions

Function concepts and program structure

User-Defined Functions

Creating and calling functions

Python Standard Library

Modules and built-in functionality

Python Arguments

Parameters, arguments and function behaviour

*args and **kwargs

Flexible function arguments

Python Scope

Variable accessibility and scope

Python Decorators

Function behaviour and advanced function concepts

Python Lambda

Anonymous functions

Python Recursion

Recursive function concepts

Python Generators

Generator functions and incremental execution


CONTINUE TO THE NEXT MODULE

Continue to Module 4: Python Collections
[https://teamacademy.help.center/article/1327-module-4-python-data-types] to
learn how Python stores, organises and manipulates different types of data using
its built-in collection structures.