Skip to Content

PCAP-31-03: Lambda Functions in Python

Learn the key characteristics of lambda functions in Python. Discover their anonymous nature and flexibility in returning values. Prepare for the PCAP-31-03 certification exam with our comprehensive guide.

Table of Contents

Question

What is true about lambda functions? (Choose two.)

A. they are called anonymous functions
B. they cannot return the None value as a result
C. they must contain the return keyword
D. they must have a non-zero number of parameters

Answer

A. They are called anonymous functions
C. They must contain the return keyword

Explanation

Lambda functions in Python are anonymous functions, meaning they are defined without a name. They are designed to be concise and used in situations where a small, one-time function is required.

Lambda functions must contain the `return` keyword implicitly. The expression following the `:` in the lambda definition is automatically returned by the function. There is no need to explicitly use the `return` statement.

Regarding the other options:
B. Lambda functions can return the `None` value as a result. There is no restriction on the type of value a lambda function can return.

D. Lambda functions can have zero or more parameters. They are not required to have a non-zero number of parameters. For example, `lambda: 42` is a valid lambda function with no parameters.

In summary, lambda functions in Python are anonymous functions that implicitly return the result of the expression defined after the `:`. They can return any value, including `None`, and can have zero or more parameters.

Python Institute PCAP-31-03 certification exam practice question and answer (Q&A) dump with detail explanation and reference available free, helpful to pass the Python Institute PCAP-31-03 exam and earn Python Institute PCAP-31-03 certification.