Western Governors University (WGU) C859 Introduction to Programming in Python Practice Test

Session length

1 / 20

Which keyword is used to define a lambda function in Python?

def

lambda

In Python, the keyword used to define a lambda function is 'lambda'. A lambda function is a small, anonymous function that is defined using the lambda keyword rather than the traditional def keyword used for regular functions.

Lambda functions can take any number of arguments but can only have one expression. The expression is evaluated and returned. This allows for quick and concise function definitions that are especially useful for short, throwaway functions that don't require a formal definition.

For example, the syntax for a lambda function is:

```python

lambda arguments: expression

```

This makes lambda a powerful tool when you need simple functionality without the overhead of defining a full function using def. The simplicity and expressiveness of lambda functions allow them to be integrated seamlessly with functions like map(), filter(), and sorted(), among others.

Hence, the correct choice is 'lambda', as it directly relates to the creation of such compact functions in Python.

function

method

Next Question
Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy