References#

🏛️ Lecture 5

ENPM605 – L5: Advanced Functions

Covers programming paradigms (procedural, functional, object-oriented), first-class functions, lambda expressions, closures, callables, decorators (basic, stacking, parameterized), functools.wraps, functools.partial, and built-in higher-order functions (map, filter, sorted with key).

🐍 Python Language References
🔧 Functional Programming HOWTO

Python HOWTO

Comprehensive guide to functional programming in Python, including iterators, generators, and built-in functional tools.

https://docs.python.org/3/howto/functional.html
📝 Lambda Expressions

Python Reference

Syntax and semantics of lambda expressions in Python.

https://docs.python.org/3/reference/expressions.html#lambda
🔍 Data Model: __call__

Python Data Model

The __call__ special method that makes instances callable.

https://docs.python.org/3/reference/datamodel.html#object.__call__
📦 Built-in: callable()

Built-in Functions

The callable() function for checking if an object is callable.

https://docs.python.org/3/library/functions.html#callable
🔄 functools.partial

Standard Library – functools

Creating partial function objects with frozen arguments.

https://docs.python.org/3/library/functools.html#functools.partial
📋 functools.wraps

Standard Library – functools

Preserving function metadata when writing decorators.

https://docs.python.org/3/library/functools.html#functools.wraps
📖 Glossary: Decorator

Python Glossary

Official definition of decorators in the Python glossary.

https://docs.python.org/3/glossary.html#term-decorator
📝 PEP 318: Decorators

PEP 318

The PEP that introduced decorator syntax for functions and methods.

https://peps.python.org/pep-0318/
📏 Style and Best Practices
📏 PEP 8 – Style Guide

Coding Conventions

Guidelines for function naming, lambda usage, and code formatting.

https://peps.python.org/pep-0008/
🌐 External Tutorials
🎯 Real Python: Primer on Decorators

Real Python

Comprehensive tutorial on decorators, including first-class objects, closures, and practical examples.

https://realpython.com/primer-on-python-decorators/
🔒 Real Python: Closures

Real Python

In-depth guide to closures in Python with practical examples.

https://realpython.com/python-closure/
🔀 Real Python: Lambda Functions

Real Python

Guide to lambda functions, their syntax, use cases, and limitations.

https://realpython.com/python-lambda/
🛠️ Real Python: functools

Real Python

Overview of the functools module including partial, wraps, lru_cache, and more.

https://realpython.com/python-functools/
🔧 Real Python: Functional Programming

Real Python

Introduction to functional programming concepts in Python.

https://realpython.com/python-functional-programming/
📚 Recommended Reading
📘 Python Official Tutorial

Getting Started

Section 4.7.5 (Lambda Expressions) and Section 4.7.6 (Documentation Strings) cover relevant topics for this lecture.

https://docs.python.org/3/tutorial/
Luciano Ramalho

Fluent Python (2nd Edition)

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

Mark Lutz

Learning Python (5th Edition)

Chapters 19-21 cover advanced function topics including closures, decorators, and functional programming tools.

Brett Slatkin

Effective Python (2nd Edition)

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