Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"print" throws an invalid syntax error in Python 3

I am brand new to python. I have been working on the courses on Codecademy. I am also currently using Pydev / LiClipse.

In one of the first lessons on Codecademy it wants you to set the variable parrot to "Norwegian Blue". Then it wants you to print the length of parrot using the len string method. It is very simple, and I got the answer right away with:

parrot = "Norwegian Blue"
print len(parrot)

When I put the exact same code into LiClipse it returned:

SyntaxError: invalid syntax

It work in LiClipse when I changed it to:

print (len(parrot))

Can someone let me know why that worked in codecademy, but not in LiClipse, and why adding the parenthesis fixed it?

like image 895
Bret Avatar asked Jul 18 '26 05:07

Bret


1 Answers

It sounds like Pydev/LiClipse is using Python 3 while Codeacademy is using python 2.x or some other older version. One of the changes made when python updated from 2.x to 3 was print is now a function.

Python 2:

print "stuff to be printed"

Python 3:

print("stuff to be printed")
like image 133
Chachmu Avatar answered Jul 20 '26 17:07

Chachmu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!