Menu
Coddy logo textTech

Syntax

Lesson 2 of 9 in Coddy's Python Lambda Functions course.

A lambda function can take any number of arguments, but can only have one expression.

This is the syntax of lambda,

lambda arguments : expression

The expression is executed and the result is returned.

Let's start with examples without arguments,

hello = lambda : print("Hello World")

To execute,

hello()  # Prints "Hello World"

Another example,

calc = lambda : 3 + 5
a = calc()  # a holds 8
challenge icon

Challenge

Easy

Create a lambda function without arguments which returns an empty list ([]), assign the lambda to empty_list variable.

You don't need to execute the lambda, we do that for you!

Try it yourself

# Write code here

All lessons in Python Lambda Functions