+ 1
Can python lambda contain the statement?
Simply speaking notation of f = lambda : x * x for x in range(10). I have read that python is not a strict language, so that we can include additional if- statement or for clause there. You can refer to Deitel Python book which cover data science and AI for higher version.
3 Respuestas
+ 4
your lambda cannot be parsed
perhaps you mean
f = lambda n: (x*x for x in range(n))
# f returns a generator expression, which can be unpacked by *
print(*f(5))
0
You can include as many statement in a single line in python if you know the way
0
RuntimeTerror
You are limited to one expression.
True, you can make it long and complicated with multiple if else ir by nesting other lambdas inside, but they all still have to be in one long expression and you often end up with code that is hard to read. Nice for flexing, but not on production code
It's better to use a regular functions for complicated cases.