3 ms·
print thing # Works in Python 2 print(thing) # the parenthesis are optional in Python 2 print(thing) # the parenthesis are required in Python 3
by fnordfnordfnord 10y ago
print thing # Works in Python 2
print(thing) # the parenthesis are optional in Python 2
print(thing) # the parenthesis are required in Python 3
A lot of problems I've encountered in the transition are a result of the huge amount of simple examples available to newcomers which are written in the Python 2 syntax.
- TheOneTrueKyle 10y agoAs someone new to python, this has been confusing. The process involves learning using some blog post, the spending time refactoring because its old.
- fnordfnordfnord 10y agoYeah, it's an unfortunate added frustration for beginners, but one you can quickly overcome, once you're made aware.
- Orangeair 10y agoSaying the parentheses are optional in Python 2 is kind of inaccurate. "print(thing)" is just "print (thing)", and "(thing)" is just an unnecessarily parenthesized version of "thing". So basically it's just redundant syntax that happens to make it look like a function. If you try to do something like "print(thing1, thing2)" in Python 2, you'll find that "(thing1, thing2)" is interpreted as a tuple, so Python prints it as a tuple (instead of printing thing1 and thing2 individually).