Home > Articles > Open Source > Python

  • Print
  • + Share This
Like this article? We recommend

Like this article? We recommend

Print Changes

This is the change that breaks most existing Python code.

print

is now

print()

Why change from a statement to a built-in function (BIF)? Having print as a statement is limiting in many regards, as detailed in van Rossum's "Python Regrets," which points out what he feels are shortcomings of the language. Having print as a statement also limits improvements to it. With a function, new keyword parameters can be added; certain standard behaviors can be overridden with keyword parameters; and it can be replaced if desired, just like any other BIF. Consider these before-and-after examples:

Python 2.x:

>>> i = 1
>>> print 'Python' 'is', 'number', i
Pythonis number 1

Python 3.x:

>>> i = 1
>>> print('Python' 'is', 'number', i)
Pythonis number 1

There are more examples in van Rossum's "What's New in Python 3.0," as well as more information about this change in Python Enhancement Proposal (PEP) 3105.

  • + Share This
  • 🔖 Save To Your Account