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 : expressionThe 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 8Challenge
EasyCreate 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