
Master the essentials of Python by learning data types, basic functions, and classes, while setting up and running code in your preferred environment with Jupyter notebooks or VS Code.
Explore the functional paradigm in Python, focusing on immutability, pure functions, and referential transparency. Discover how first-class and higher-order functions, plus recursion, shape data and behavior into predictable code.
Explore functions as first class objects in Python, showing how to pass functions as arguments and invoke them via callable references within another function.
Learn how functions return other functions to form closures, with an outer function's arguments accessible to an inner function and the outer returning the inner reference for patterns like decorators.
Implement reverse_args, a function that takes a two-argument function and swaps its arguments, turning subtract(10, 5) into -5 as explored in the previous lecture.
Define a reverse args function in Python that wraps a two-argument function, swaps the arguments, and returns the wrapper, then test with reversed inputs to produce correct results.
Explore how first-class functions can be stored in data structures like lists, dictionaries, and sets in Python, enabling dynamic programs and function application via unpacking and iteration.
Implement a simple calculator in Python that supports addition, subtraction, multiplication, and division, prompts the user to select an operation and enter two numbers, and handles division by zero.
Learn to implement add, subtract, multiply, and divide in Python, using the operator module, map them in a dictionary, collect user input, and invoke the function to produce the result.
Explore higher order functions in Python, which take or return functions, enabling abstraction over actions and creating concise, readable code with practical apply examples like doubling a number.
Develop a higher-order retry function that accepts a max tries and a function, retrying until success or until the limit is reached, with testing on an unstable function.
Define a retry higher-order function in Python that retries a function up to three times by default using a for loop, with an optional max retries and value error handling.
Define pure functions as those that always output the same result for the same input and have no side effects, unlike impure procedures like update profile that modify external state.
Identify and remove side effects to turn impure functions into pure ones by isolating changes. Return a new, non-destructive database copy instead of in-place updates, using deep copies when needed.
Explore lazy versus eager evaluation in Python, contrasting list comprehensions and generator expressions to defer computations and improve performance with large data, while embracing immutability and referential transparency.
Define generator functions with def, yield values, and chain lazy operations to build pipelines—computing evens and their squares—while contrasting lazy and eager evaluation in Python.
Explore immutability in functional programming, showing how immutable data supports pure functions and how to add to a Python list without side effects by creating a new list.
Convert an imperative list operation into a pure function by avoiding mutation and embracing immutability. Learn how to add a value to every list element without altering the original data.
See how Python list comprehensions transform a data list of integers into a new list of each item plus value, without mutating the original argument.
Explore immutable state management in functional programming by building a text history with a history object, states, and a current index, enabling undo and redo with pure functions.
Explore aliasing in Python and how two variables can share the same mutable object, causing unintended side effects. Learn how immutable data structures mitigate these risks by creating new objects.
Explore anonymous Python functions, known as lambdas, and contrast them with def functions, highlighting inline, single-expression usage in a higher order function and list comprehensions.
Explore how lambdas reflect a single Python expression, from squaring numbers to conditional logic with lists, while weighing readability and when to prefer regular functions.
Learn why Python lambdas should be single expression, simple, and readable rather than complex one-liners. Discover when to use regular functions for maintainability, documentation, and safe reuse, avoiding readability monsters.
Learn to invoke anonymous lambdas on the fly with arguments, handle single-parameter cases, and recognize readability risks of chaining or nesting lambdas, including when to avoid them.
In this skill challenge, define a lambda called ternary to simulate a ternary operation that evaluates the sine of a number and yields positive, negative, or zero, practicing functional programming.
Implement a lambda that classifies a number as positive, negative, or zero by chaining ternary expressions in Python.
Welcome to the best and most comprehensive introduction to functional programming in Python!
In this beginner-friendly course, you will get to learn and practice Python's functional capabilities step-by-step, from the ground up.
The course will begin with a conceptual understanding of the key tenets of functional programming:
immutability: the idea that data should not be modified in place
purity: the practice of writing functions that do not cause side effects
higher-order functions: treating functions as pari passu with other data types
recursion: the pattern of writing functions that call themselves
referential transparency: the principle that a function call can be replaced with its return value without changing the program's behavior
Then, we will explore practical utilities that Python offers to help us write functional code, including:
map, filter, reduce, zip, any, all: utilities for working with iterables
list, set, dictionary, and generator comprehensions: concise ways of creating lists, sets, dictionaries, and generators
generator functions and iterators: functions that can be paused and resumed
variable arity: functions that can take a variable number of arguments, unknown at the time of writing the function
In the final, and longest part of the course, we will take a look at more advanced topics, including:
closures: higher-order functions that can access non-local variables
recursion: functions that call themselves
partial function application: functions that return other functions, with some arguments pre-filled
currying: a special case of partial function application
memoization: caching the results of function calls to speed up execution
infinite iterators: iterators that never end
functional overloading: functions that behave differently depending on their inputs
Throughtout the course, you will get to practice your newly acquired skills through a set of more than 20 skill challenges, each of which will be followed with a detailed video explanation of the solution that we will walk through together.
This course is very beginner-friendly and no python experience is assumed. If you've never worked with Python before, there's a full length introduction to Python programming included as an appendix, covering the fundamentals of the language from the basic data types to containers, control flow, loops, classes, and more.
See you inside!