-5

I just installed 3.4 on a new machine, tried to run something I know works and it failed. I then tried to just type the following into IDLE and it failed:

>>> print 'hello'
SyntaxError: invalid syntax
>>> print hello
SyntaxError: invalid syntax
>>> print "hello"
SyntaxError: invalid syntax
>>> 

I am confused as to why that would fail.

Aoxx
  • 55
  • 13

2 Answers2

2

According to Python3.0.1 documentation

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

so try: print ("hello")

vaultah
  • 40,483
  • 12
  • 109
  • 137
Buzz
  • 1,821
  • 22
  • 25
1

I believe with Python 3+ you need parens. Try this:

print("Hello")

Here is my test:

Python 3.3.2 (default, Sep 15 2013, 13:36:01)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print 'hello'
  File "<stdin>", line 1
    print 'hello'
                ^
SyntaxError: invalid syntax
>>>
>>>
>>> print("Hello")
Hello
>>>
vaultah
  • 40,483
  • 12
  • 109
  • 137
ProfessionalAmateur
  • 4,237
  • 9
  • 44
  • 62