mirror of
https://github.com/rasbt/python_reference.git
synced 2025-02-20 15:22:08 +00:00
mutable objects as default arguments
This commit is contained in:
parent
a305b990c4
commit
9483e549c3
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:611615765638a390c8e9093179758c4a23524ddcc2379aeff80e51c22031aa18"
|
||||
"signature": "sha256:913662e78e4e0a2e83e289d74c42e197b1d5af6c2f589057de821734b0141c07"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
|
@ -229,7 +229,7 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Another popular example to illustrate the reuse of objects for small integers is:"
|
||||
"#### Another popular example to illustrate the reuse of objects for small integers is:"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -257,7 +257,7 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"And to illustrate the test for equality (`==`) vs. identity (`is`):"
|
||||
"#### And to illustrate the test for equality (`==`) vs. identity (`is`):"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -266,8 +266,8 @@
|
|||
"input": [
|
||||
"a = 'hello world!'\n",
|
||||
"b = 'hello world!'\n",
|
||||
"print('a is b', a is b)\n",
|
||||
"print('a == b', a == b)"
|
||||
"print('a is b,', a is b)\n",
|
||||
"print('a == b,', a == b)"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
|
@ -276,12 +276,41 @@
|
|||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"a is b False\n",
|
||||
"a == b True\n"
|
||||
"a is b, False\n",
|
||||
"a == b, True\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 3
|
||||
"prompt_number": 6
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#### And this example shows when `==` does not necessarilu implies that two objects are the same:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"a = float('nan')\n",
|
||||
"print('a == a,', a == a)\n",
|
||||
"print('a is a,', a is a)"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"a == a, False\n",
|
||||
"a is a, True\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 7
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:611615765638a390c8e9093179758c4a23524ddcc2379aeff80e51c22031aa18"
|
||||
"signature": "sha256:913662e78e4e0a2e83e289d74c42e197b1d5af6c2f589057de821734b0141c07"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
|
@ -229,7 +229,7 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Another popular example to illustrate the reuse of objects for small integers is:"
|
||||
"#### Another popular example to illustrate the reuse of objects for small integers is:"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -257,7 +257,7 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"And to illustrate the test for equality (`==`) vs. identity (`is`):"
|
||||
"#### And to illustrate the test for equality (`==`) vs. identity (`is`):"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -266,8 +266,8 @@
|
|||
"input": [
|
||||
"a = 'hello world!'\n",
|
||||
"b = 'hello world!'\n",
|
||||
"print('a is b', a is b)\n",
|
||||
"print('a == b', a == b)"
|
||||
"print('a is b,', a is b)\n",
|
||||
"print('a == b,', a == b)"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
|
@ -276,12 +276,41 @@
|
|||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"a is b False\n",
|
||||
"a == b True\n"
|
||||
"a is b, False\n",
|
||||
"a == b, True\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 3
|
||||
"prompt_number": 6
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#### And this example shows when `==` does not necessarilu implies that two objects are the same:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"a = float('nan')\n",
|
||||
"print('a == a,', a == a)\n",
|
||||
"print('a is a,', a is a)"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"a == a, False\n",
|
||||
"a is a, True\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 7
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
|
|
Loading…
Reference in New Issue
Block a user