Skip to content

Commit 2d6c4aa

Browse files
print.xml: add advanced note on print as statement
including explanation of its behavior when printing tuples and the option of using from __future__ import print_function closes jdf#63
1 parent c686c43 commit 2d6c4aa

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎Reference/api_en/print.xml‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,16 @@ print(list_of_stuff)
2525
The <b>print()</b> function writes to the console area, the black rectangle at the bottom of the Processing environment. This function is often helpful for looking at the data a program is producing.<br/>
2626
<br />
2727
Using <b>print()</b> on an object will output a string representation of that object, as determined by its internal <b>__str__</b> and <b>__repr__</b> methods (<a href="http://stackoverflow.com/a/2626364">more information here</a>).<br/><br/>
28-
In Python Mode, <b>print()</b> and <b>println()</b> are functionally identical.
28+
In Python Mode, <b>print()</b> and <b>println()</b> are functionally identical.<br />
29+
<br/ >
30+
Under the hood, <b>print</b> in Python 2 is not actually a function at all--it
31+
is a statement, and can be used without quotes: <b>print i</b>. Writing
32+
<b>print(i)</b> is <b>print</b> plus the single-element expression <b>(i)</b>.
33+
When we write <b>print(1,2)</b>, the statement outputs a tuple: <b>(1, 2)</b>.
34+
To change this behavior, make the first line of a sketch: <b>from __future__
35+
import print_function</b>. This turns <b>print(i)</b> into a function, disallows
36+
<b>print i</b>, and causes <b>print(1, 2)</b> to output <b>1, 2</b> rather than
37+
<b>(1, 2)</b>.
2938
]]></description>
3039

3140
<syntax>

0 commit comments

Comments
 (0)