Why doesn’t this work?
lambda: print "x"
Is this not a single statement, or is it something else?
The documentation seems a little sparse on what is allowed in a lambda…
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A
lambda‘s body has to be a single expression. In Python 2.x,printis a statement. However, in Python 3,printis a function (and a function application is an expression, so it will work in a lambda). You can (and should, for forward compatibility 🙂 use the back-ported print function if you are using the latest Python 2.x: