Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy print statement is not pythonic?
    text
    copied!<p>This question was bugging me for quite a while (as evidenced by <a href="https://stackoverflow.com/questions/933214/what-are-the-used-unused-features-of-python-3">my previous question</a>): why exactly is <code>print(x)</code> better (which is defined as being more pythonic) than <code>print x</code>?</p> <p>For those who don't know, the <code>print</code> statement was changed into function in Python 3.0. The formal documentation is in <a href="http://www.python.org/dev/peps/pep-3105/" rel="nofollow noreferrer">PEP 3105</a> and motivation is in <a href="http://mail.python.org/pipermail/python-dev/2005-September/056154.html" rel="nofollow noreferrer">Guido van Rossum's email</a>.</p> <p>To those points I would like to make a counterpoint:</p> <ol> <li>There are other operators, such as <code>import</code> which we write as a statement, though their functionality is actually duplicated with a function <code>__import__</code> <ul> <li>To beginners, the operator <code>print</code> does not belong to the general application logic. To them it's the mysterious operator which is a culmination of their program. They expect it to look differently.</li> <li>All the beginner books which were describing basic Python 2.x are now <em>guaranteed to be broken from the first example</em>. Certainly, languages sometimes change, but those changes are usually less visible to novices. </li> <li>It's not immediately obvious to me that a functionality of <code>print</code> can be duplicated on an application level. For example, sometimes I would like to redirect print from a console as a modal OS dialog. </li> <li>While people say it's hard to rewrite all <code>print</code> statements to a function, they have forced every Python 2.x developer to do exactly that for all their projects. Good, it's not hard with automatic converter.</li> <li>Everyone who enjoys having an ability to manipulate function <code>print</code> would be just as well-served if <code>print</code> was a statement wrapping function <code>__print__</code>.</li> </ul></li> </ol> <p>So, can we please have a canonical answer to this question on the pages of Stack Overflow?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload