I am using Python 3.2.2
>>> s = 'hhh'
>>> print s
SyntaxError: invalid syntax
>>> print(s)
hhh
>>> print 2*2
SyntaxError: invalid syntax
>>> print(2*2)
4
Why do I have to use print("...")
to print something? If I dno't it complains with 'SyntaxError'.
No, you cannot. The print statement is gone in Python 3; the compiler doesn't support it anymore. This will remove support for the print statement in Python 2 just like it is gone in Python 3, and you can use the print() function that ships with Python 2.
It is because you are iterating over the set numbers . The loop runs and the print() function automatically inserts a \n at the end of each item it prints out for display. Hence each item is being displayed on its own line. By default, the end argument is set to \n .
Python print() FunctionThe print() function prints the specified message to the screen, or other standard output device. The message can be a string, or any other object, the object will be converted into a string before written to the screen.
To print anything in Python, you use the print() function – that is the print keyword followed by a set of opening and closing parentheses, () .
As of python 3.0, print
is a function. See:
http://docs.python.org/release/3.0.1/whatsnew/3.0.html#print-is-a-function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With