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