Because it is used to make the new function object and return them in runtime.
The reason lambda forms in Python do not have statements is because lambda functions are designed to be simple, anonymous functions that can be defined in a single line. They are meant for small, one-off functions where using a full function definition would be overkill.
Lambda functions are restricted to a single expression, which means they cannot contain multiple statements. Allowing statements in lambda functions would make them more complex and defeat their purpose of being concise and easy to use.
Additionally, lambda functions are often used in situations where functions are expected as arguments, such as in the map()
, filter()
, and sorted()
functions. Allowing statements in lambda functions would make it harder to use them in these contexts where only expressions are allowed.
So, to summarize, lambda functions in Python do not have statements to keep them simple, concise, and suitable for their intended use cases.