mirror of
https://github.com/rasbt/python_reference.git
synced 2024-11-23 20:11:13 +00:00
note about print tuple
This commit is contained in:
parent
f9d17a4f94
commit
3f28b768e0
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:2d8d614150aba437b28f7fe22d2e6a05b76ddb1a447d645c7d5085ab0c286c44"
|
||||
"signature": "sha256:3442b8345ce99d8d379e475a753f23abf3392c6d4a6fdf185cf061e73e09b9e1"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
|
@ -151,13 +151,13 @@
|
|||
"<tr><td>generators</td>\n",
|
||||
"<td>2.2.0a1</td>\n",
|
||||
"<td>2.3</td>\n",
|
||||
"<td><a class=\"pep reference external\" href=\"http://www.python.org/dev/peps/pep-0255\"><strong>PEP 255</strong></a>:\n",
|
||||
"<td><a href=\"http://www.python.org/dev/peps/pep-0255\"><strong>PEP 255</strong></a>:\n",
|
||||
"<em>Simple Generators</em></td>\n",
|
||||
"</tr>\n",
|
||||
"<tr><td>division</td>\n",
|
||||
"<td>2.2.0a2</td>\n",
|
||||
"<td>3.0</td>\n",
|
||||
"<td><<a class=\"pep reference external\" href=\"http://www.python.org/dev/peps/pep-0238\"><strong>PEP 238</strong></a>:\n",
|
||||
"<td><a href=\"http://www.python.org/dev/peps/pep-0238\"><strong>PEP 238</strong></a>:\n",
|
||||
"<em>Changing the Division Operator</em></td>\n",
|
||||
"</tr>\n",
|
||||
"<tr><td>absolute_import</td>\n",
|
||||
|
@ -198,7 +198,7 @@
|
|||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"prompt_number": 3
|
||||
"prompt_number": 1
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
|
@ -227,10 +227,9 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"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). \n",
|
||||
"In contrast, Python 3 would raise a `SyntaxError` if we called the print function the Python 2-way without the parentheses. \n",
|
||||
"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 `print()` function, meaning that we have to wrap the object that we want to print in parantheses. \n",
|
||||
"\n",
|
||||
"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."
|
||||
"Python 2 doesn't have a problem with additional parantheses, but in contrast, Python 3 would raise a `SyntaxError` if we called the print function the Python 2-way without the parentheses. \n"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -324,6 +323,38 @@
|
|||
],
|
||||
"prompt_number": 3
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Note:**\n",
|
||||
"\n",
|
||||
"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 `print` is a \"statement\" in Python 2, not a function call."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"print 'Python', python_version()\n",
|
||||
"print('a', 'b')\n",
|
||||
"print 'a', 'b'"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"Python 2.7.6\n",
|
||||
"('a', 'b')\n",
|
||||
"a b\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 4
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
|
|
Loading…
Reference in New Issue
Block a user