CHAPTER 30   •   PYTHON

Python Lambda

Learn how to create small anonymous functions.

01 What is this?

Learn how to create small anonymous functions.

02 Syntax

Python Syntax
lambda arguments: expression

03 Example

Python Example
square = lambda x: x * x
print(square(5))

04 Important Points

Lambda functions are useful for short operations.

05 Common Mistakes

Avoid using complex logic inside lambda expressions.

06 Real World Use

Lambda functions are often used with map, filter and sorting.

07 Practice This Topic

Now try the example yourself in the AIFA Python Editor.

  • Read the example carefully.
  • Change the values.
  • Run the code.
  • Observe the output.
  • Try creating your own example.
Try It Yourself →