0

Is the expression inside the [..] compilable for others expressions ?

Such as ; print(i**3) for i in range(11)

19th Jan 2022, 11:43 AM
C A-D
C A-D - avatar
5 Respuestas
+ 2
[print(i**3) for i in range(11)] [repr(i**3) for i in range(11)] "In Python 2, print is a statement, not a function" https://docs.python.org/2.7/reference/simple_stmts.html#print Seems nobody has given a deeper reason.
19th Jan 2022, 12:12 PM
FanYu
FanYu - avatar
+ 1
Because you forgot the set of opening and closing parenthesis and put an extra one in. print(i**3 for i in range(11))
19th Jan 2022, 12:01 PM
Slick
Slick - avatar
+ 1
d = {} [d.update({i:i}) for i in range(11)] [d[i]=i for i in range(11)] a = lambda x: 1 a = lambda x: x=1 Finally found a clear explanation!🤣 "A statement in Python is a line of code that provides instruction or commands for Python to perform. A statement never returns any value. Functions on the other hand are a collection of statements that when called perform an intended action. They are organized and reusable in nature. Functions always return a value." https://www.pylenin.com/blogs/python-print/
19th Jan 2022, 12:48 PM
FanYu
FanYu - avatar
0
Did you try it or just ask blindly?
19th Jan 2022, 11:44 AM
Slick
Slick - avatar
0
I've try on different compiler it seems to not work but i don't understand why ?
19th Jan 2022, 11:45 AM
C A-D
C A-D - avatar