Reputation: 1
I have googled the whole internets and can't find the reason why I get this error when using range() function:
>>> for x in range(5):
print "Hello World!"
SyntaxError: invalid syntax
I expect 5 Hello Worlds there.
It's ok on Python 2.7, but on Python 3.3.3 (64bits, Windows 8.1) I get this error. Could anybody advice how can I make loops in Python 3.3.3? Is it bug or something has changed a lot since 2.7 regarding "For"?
Thanks. :/
Upvotes: -2
Views: 2486
Reputation: 4178
In python 3 and above print is a function so try writing
for x in range(5): print("Hello World!")
Upvotes: 0
Reputation: 36181
print
is a function in Python 3, you need to put parentheses:
for x in range(5):
print("Hello World!")
From the official website:
The print statement has been replaced with a print() function, with keyword arguments to replace most of the special syntax of the old print statement (PEP 3105).
Upvotes: 2
Reputation: 34176
In Python 3.x, print
is a function, so you must call it with parentheses ()
:
print("Hello World!")
Upvotes: 0