Saturday, June 17, 2017

Summer of code 2017: SyntaxError: Missing parentheses in call to 'print'


As explained in my Summer of code 2017: Python post I decided to pick up Python

I looked at some examples and when I tried to run them I was getting an error

It was a pretty simple print statement

print 'Hello world'

Running that produced an error


Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> print 'Hello world'
SyntaxError: Missing parentheses in call to 'print'

It tuns out, the example I was looking at was for Python 2. In Python 2, print was a distinct statement, in Python 3 print is actually a function call. Function calls require parentheses

If I changed the print statement to the following by adding parentheses.

>>> print ('Hello world')
Hello world

Running that worked fine.

Maybe this will help some other poor soul in the future......

No comments: