Why this does not work?
[ print("%d03" % a) for a in range(1,99)]
File "<stdin>", line 1
[ print("%d03" % a) for a in range(1,99)]
^
SyntaxError: invalid syntax
but
print(“%03d” % a)
098
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.
In Python 2.x,
printis a statement, so it cannot appear as part of an expression. In Python 3.x, the list comprehension would be syntactically correct becauseprintwas turned into a function, though a bit pointless sinceprint()always returnsNone.In any case, this is the right way to do it: