Forums

Difference between python 2.7 and 3.4

Hi everyone i am a total newbee at python and have one question that i hope you can help me with:

When i type the following code in 2.7:

import math everything = dir(math) print everything ( it showes every function in the math libary)

in gives me the correct answer

when i type the same code in python 3.4 the following error turns up:

import math

everything = dir(math) print everything File "<stdin>", line 1 print everything ^ SyntaxError: invalid syntax

Does anyone know why python 3.4 turns up the error?

In Python 3, print is a function. So you have to add brackets:

print(everything)

You can use the brackets in Python 2.7 as well, it's just that they're not required. It's a good idea if you want to make code that can run in either version of Python though, maybe a good habit to get into...

Thanks :-)!