+ 1
why error: s = lambda a: a=4
The conditions of the assignment from the "code challenges": What is the output of this code? s = lambda a: a=4 print(s(2)) This is a question from the local mini-games "code challenges" and the correct answer is an error. My level of knowledge so far does not allow me to understand why exactly the error, read a few other resources and still do not understand. Hope for your help
5 Respostas
+ 3
It is a question from the challenges (play against other users).
Lambda functions can only contain expressions. An assignment is not an expression.
+ 4
If you want to check if the parameter to the lambda is equal to 4, you should use ==
+ 1
Can you specify which course and which lesson?
Or give a complete description of the task and your full solution.
+ 1
Not sure which python they are running here, but as of 3.8 you can use the walrus operator( :=) inside a lambda. So I would try changing it to
s = lambda a: a := 4
0
The conditions are defined by the game "code challenges"