What is the difference between Python 2.7 and Python 3?

Question

What is the difference between Python 2.7 and Python 3?

Answer

Python 3 is the newer version of the language, but Python 2.7 (the legacy version) is still very widely used, so it’s useful to be familiar with both.

In general, the syntax for Python 2.7 and Python 3 remains pretty similar. Though one notable difference is that in Python 3, the print statement is now a function and requires parentheses, whereas they didn’t in Python 2.7.

Python 3:

print("Hello, world!")

Python 2.7:

print "Hello, world!"

See here for more differences between the two versions, as well as for some information about the __future__ module (which helps with compatibility).

1 Like

Thanks for the above explanation. Can anyone offer a slightly deeper comparison in syntax, and any other impacts of the change. What was the driver for the change? I’m guessing they didn’t release a whole new version to change the way we print :stuck_out_tongue:

the word here is a clickable link, which contains additional information?

1 Like