mirror of
https://github.com/rasbt/python_reference.git
synced 2024-11-27 14:01:15 +00:00
note about print tuple
This commit is contained in:
parent
3f28b768e0
commit
667a7333cd
|
@ -1848,7 +1848,7 @@ generators
|
|||
2.3
|
||||
</td>
|
||||
<td>
|
||||
<a class="pep reference external" href="http://www.python.org/dev/peps/pep-0255"><strong>PEP 255</strong></a>: <em>Simple Generators</em>
|
||||
<a href="http://www.python.org/dev/peps/pep-0255"><strong>PEP 255</strong></a>: <em>Simple Generators</em>
|
||||
</td>
|
||||
</tr>
|
||||
<tr><td>
|
||||
|
@ -1861,7 +1861,7 @@ division
|
|||
3.0
|
||||
</td>
|
||||
<td>
|
||||
<<a class="pep reference external" href="http://www.python.org/dev/peps/pep-0238"><strong>PEP 238</strong></a>: <em>Changing the Division Operator</em>
|
||||
<a href="http://www.python.org/dev/peps/pep-0238"><strong>PEP 238</strong></a>: <em>Changing the Division Operator</em>
|
||||
</td>
|
||||
</tr>
|
||||
<tr><td>
|
||||
|
@ -1927,7 +1927,7 @@ unicode_literals
|
|||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">
|
||||
In [3]:
|
||||
In [1]:
|
||||
</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
|
@ -1972,8 +1972,8 @@ In [3]:
|
|||
</div>
|
||||
<div class="inner_cell">
|
||||
<div class="text_cell_render border-box-sizing rendered_html">
|
||||
<p>Very trivial, and the change in the print-syntax is probably the most widely known change, but still it is worth mentioning: Python 2's print function doesn't require the parantheses for invoking the print function (it wouldn't choke on them).<br />In contrast, Python 3 would raise a <code>SyntaxError</code> if we called the print function the Python 2-way without the parentheses.</p>
|
||||
<p>I think this change in Python 3 makes sense in terms of consistency, since it is the common way in Python to invoke function calls with its parentheses.</p>
|
||||
<p>Very trivial, and the change in the print-syntax is probably the most widely known change, but still it is worth mentioning: Python 2's print statement has been replaced by the <code>print()</code> function, meaning that we have to wrap the object that we want to print in parantheses.</p>
|
||||
<p>Python 2 doesn't have a problem with additional parantheses, but in contrast, Python 3 would raise a <code>SyntaxError</code> if we called the print function the Python 2-way without the parentheses.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -2110,6 +2110,51 @@ In [3]:
|
|||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="cell border-box-sizing text_cell rendered">
|
||||
<div class="prompt input_prompt">
|
||||
</div>
|
||||
<div class="inner_cell">
|
||||
<div class="text_cell_render border-box-sizing rendered_html">
|
||||
<p><strong>Note:</strong></p>
|
||||
<p>Printing "Hello, World" above via Python 2 looked quite "normal". However, if we have multiple objects inside the parantheses, we will create a tuple, since <code>print</code> is a "statement" in Python 2, not a function call.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">
|
||||
In [4]:
|
||||
</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class="highlight"><pre><span class="k">print</span> <span class="s">'Python'</span><span class="p">,</span> <span class="n">python_version</span><span class="p">()</span>
|
||||
<span class="k">print</span><span class="p">(</span><span class="s">'a'</span><span class="p">,</span> <span class="s">'b'</span><span class="p">)</span>
|
||||
<span class="k">print</span> <span class="s">'a'</span><span class="p">,</span> <span class="s">'b'</span>
|
||||
</pre></div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="output_wrapper">
|
||||
<div class="output">
|
||||
|
||||
|
||||
<div class="output_area"><div class="prompt"></div>
|
||||
<div class="output_subarea output_stream output_stdout output_text">
|
||||
<pre>
|
||||
Python 2.7.6
|
||||
('a', 'b')
|
||||
a b
|
||||
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="cell border-box-sizing text_cell rendered">
|
||||
<div class="prompt input_prompt">
|
||||
|
|
Loading…
Reference in New Issue
Block a user