References#

πŸ›οΈ Lecture 4

ENPM605 – L4: Function Fundamentals

Covers function definition and calling, arguments (positional, default, keyword, *args, **kwargs), scopes and the LEGB rule, pass-by-assignment, type hints (Optional, Union, pipe syntax), Google-style docstrings, and recursion.

🐍 Python Language References
πŸ”§ Defining Functions

Tutorial – Control Flow

Function definition, parameters, return values, and default arguments.

https://docs.python.org/3/tutorial/controlflow.html#defining-functions
πŸ“¦ More on Defining Functions

Tutorial – Control Flow

Advanced argument handling, *args, **kwargs, and unpacking.

https://docs.python.org/3/tutorial/controlflow.html#more-on-defining-functions
πŸ” Scopes and Namespaces

Tutorial – Classes

Python’s scope rules, the LEGB lookup order, and namespace mechanics.

https://docs.python.org/3/tutorial/classes.html#python-scopes-and-namespaces
πŸ“ typing Module

Standard Library – typing

Type hints, Optional, Union, and generic types.

https://docs.python.org/3/library/typing.html
πŸ”„ Pass by Reference FAQ

Python FAQ

Explanation of how Python passes arguments and why it is neither pass-by-value nor pass-by-reference.

https://docs.python.org/3/faq/programming.html#how-do-i-write-a-function-with-output-parameters-call-by-reference
πŸ” Recursion

Tutorial – Control Flow

Recursive function examples and the Fibonacci sequence.

https://docs.python.org/3/tutorial/controlflow.html#defining-functions
πŸ“‹ Function Annotations

Tutorial – Control Flow

How to use function annotations for parameter and return type hints.

https://docs.python.org/3/tutorial/controlflow.html#function-annotations
πŸ“– Docstring Conventions

PEP 257

Docstring conventions for modules, functions, classes, and methods.

https://peps.python.org/pep-0257/
πŸ“ Style and Best Practices
πŸ“ PEP 8 – Style Guide

Coding Conventions

Guidelines for function naming, parameter formatting, and documentation.

https://peps.python.org/pep-0008/
πŸ“ PEP 484 – Type Hints

Type Hints

The PEP that introduced type hints to Python.

https://peps.python.org/pep-0484/
πŸ“ PEP 604 – Union with X | Y

Simplified Union Syntax

The PEP that introduced X | Y syntax as an alternative to Union[X, Y] in Python 3.10+.

https://peps.python.org/pep-0604/
πŸ“‹ Google Python Style Guide

Docstrings Section

Google’s conventions for writing docstrings, including Args, Returns, and Raises sections.

https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings
πŸ“š Recommended Reading
πŸ“˜ Python Official Tutorial

Getting Started

Section 4.7 (Defining Functions) and Section 4.8 (More on Defining Functions) cover this lecture’s topics.

https://docs.python.org/3/tutorial/
Mark Lutz

Learning Python (5th Edition)

Chapters 16-21 cover function basics, scopes, arguments, and advanced function topics in depth.

Luciano Ramalho

Fluent Python (2nd Edition)

Chapters 7-9 cover first-class functions, type hints, decorators, and closures. Excellent for understanding functions as objects.

Brett Slatkin

Effective Python (2nd Edition)

Items 19-26 cover function arguments, return values, closures, and decorators with practical best practices.