For which version of python is 'print x' right syntax?

I have downloaded a lot of pythons codes from someone’s webpage.

Unfortunately, in his codes, he has a lot of

print x 

This is wrong syntax in my python. In my case, I have to write ‘print(x)’.

For which version of python is this ok? I am thinking of using old stuff.

That is version 2 of Python.

1 Like

Yes, the code is very old and you will probably not be able to get any benefit from it. The newest version that will support this is 2.7, and that is almost four years out of date. It would be comparable to using Windows 7 as your operating system. (There are people who have a real need to maintain such old code on old systems; but those people would not need to ask the question.)

1 Like

And by “out of date” you mean “has been unsupported for that long”. It hasn’t had significant new features since 2010.


Yes, that was imprecise.

Windows 7 had a similar release date and also a similar “end of extended support” date, so I like to use it as a point of comparison.

But not wrong :slight_smile: I wanted to emphasize just HOW far beyond expiration date Python 2 is. Like, if I find some chocolate that’s been sitting in the back of the pantry for four years, I’ll happily eat it… but maybe not a packet of pasta of the same age.

Just make sure there are no tears or stray holes in any of these. :grin:


You might want to consider whether it is practical to revise the code from Python 2 to Python 3. See the following for a summary of some of the differences between the versions:

If the revision could be done, that may be best in the long run, rather than your continuing to work with the old code.

You are likely thinking of port-a-punch cards, eg IBM Port-A-Punch; and that guy “Chad” who became infamous for helping to sort-out US-democracy back in 2000 - only something like an 029 Card Punch would add the printed version of the holes-encoded data, whereas the manual equivalents did not. I don’t recall a loose-chad problem from using an 029.

That said, recommend the OP search for newer/better/faster code…

@wdlang06, how much code did you download? If it is a few hundred lines or so, or even a thousand, and if you could practice Python 3 sufficiently to become comfortable with it, then adapt the Python 2 code accordingly, line by line. You’ll obviously be placing lots of parentheses around expressions associated with the Python 2 print command, so that they become calls to the Python 3 print function instead.

There are other issues to be concerned with as well, as Brett Cannon’s comparison of the two versions that is referenced above will inform you. For instance, devote close attention to the Division section, as some of the behavior of the single slash / operator has changed. You may need to switch some of the / operators to the // operator, for example, where division involving two int operands needs to guarantee an int result.

There are lots of details involved, but if you like programming with Python, it may be fun. Best of success to you! :slight_smile:

1 Like