Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python3 print statement doesn't work as expected

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'.

like image 272
q0987 Avatar asked Sep 28 '11 02:09

q0987


People also ask

Is print () supported in Python 3?

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.

Why SEP is not working in Python?

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 .

How do I print in Python 3?

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.

How do you print a value in Python?

To print anything in Python, you use the print() function – that is the print keyword followed by a set of opening and closing parentheses, () .


1 Answers

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

like image 140
BlackJack Avatar answered Oct 16 '22 10:10

BlackJack