Lesson 15 of 55
9 mins readPython Anonymous Lambda Expressions (\x -> expr)
In Plain English
Anonymous functions (lambdas) are written with a backslash \ (resembling the Greek letter λ) followed by parameter names and an arrow ->.
Deep Dive: How It Works
Lambda Syntax: \x -> x * 2 is an anonymous function taking x and returning x * 2.
Multi-Parameter Lambdas: \x y -> x + y takes two parameters.
Inline Callbacks: Ideal for one-off callbacks in map, filter, and fold operations.
Core Rules to Remember

Backslash \ Notation: Represents lambda λ in plain ASCII text.

One-Off Transformations: Avoid defining named top-level functions for trivial transformations.
Live Interactive Example
Hit Run Code to see it liveLambdas in Higher-Order Functions
Python 3.12
1
2
3
4
5
6
7
8
9
10
Output Console
Click "Run Code" to view the rendered output.
How it works: \x -> x^2 maps over numbers. zipWith applies \a b -> a + b*10 to pairs.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Filter Elements with Lambda
Use `filter (\x -> x > 15) [10, 20, 5, 25, 30]` and print the result.
1
2
3
4
5
6
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.