Py Lambda — Free Python Tutorial
Learn Py Lambda in Python with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.
TL;DR: Learn Py Lambda in Python with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.
Written & reviewed by the Syllab.in Academic Team (CBSE/NCERT subject experts) · Updated
Py Lambda in Python
A lambda function is a small, anonymous (nameless) function defined in a single line. It's useful when you need a simple function for a short time — especially as an argument to other functions.
Syntax: lambda arguments: expression. A lambda can take multiple arguments but has only one expression (which is automatically returned). It cannot contain if/else blocks (unless as a ternary expression) or loops.
Lambda is most commonly used with: sorted() for custom sort keys, map() to apply a function to every item, filter() to select items meeting a condition. These are called "higher-order functions".
Py Lambda — Syntax
# Regular function vs lambda: def square(x): return x**2 square_lambda = lambda x: x**2 # Multi-argument lambda: add = lambda x, y: x + y # Lambda as sort key: sorted(students, key=lambda s: s['marks'])
Learn Py Lambda step by step with Syllab's free interactive Python tutorial — runnable code examples, practice exercises and instant AI feedback, all free with no signup. Explore the full Python course →