mirror of
https://github.com/rasbt/python_reference.git
synced 2024-11-24 04:21:15 +00:00
mutable objects as default arguments
This commit is contained in:
parent
7b07896b8e
commit
2e975a9c30
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:1b145c7412627e0fa1c08e3b663174712154077c8d8b7740f66d3021a06216a4"
|
||||
"signature": "sha256:86ce70b81c4443d14b2e1a1a75e03c712874e6321abf744f5ecaae9181032e2f"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
|
@ -200,7 +200,9 @@
|
|||
"This oddity occurs, because Python tends to stores small integers as the same object, but not so for larger ones! \n",
|
||||
"(*I received a comment that this is in fact a CPython artefact and must not necessarily be true in all implementations of Python!*)\n",
|
||||
"\n",
|
||||
"So the take home message is: always use \"==\" for equality, \"is\" for identity!"
|
||||
"So the take home message is: always use \"==\" for equality, \"is\" for identity!\n",
|
||||
"\n",
|
||||
"Here is a [nice article](http://python.net/%7Egoodger/projects/pycon/2007/idiomatic/handout.html#other-languages-have-variables) explaining it using \"boxes\" (for people with C background) and \"name tags\" (in the case of Python):"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:1b145c7412627e0fa1c08e3b663174712154077c8d8b7740f66d3021a06216a4"
|
||||
"signature": "sha256:86ce70b81c4443d14b2e1a1a75e03c712874e6321abf744f5ecaae9181032e2f"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
|
@ -200,7 +200,9 @@
|
|||
"This oddity occurs, because Python tends to stores small integers as the same object, but not so for larger ones! \n",
|
||||
"(*I received a comment that this is in fact a CPython artefact and must not necessarily be true in all implementations of Python!*)\n",
|
||||
"\n",
|
||||
"So the take home message is: always use \"==\" for equality, \"is\" for identity!"
|
||||
"So the take home message is: always use \"==\" for equality, \"is\" for identity!\n",
|
||||
"\n",
|
||||
"Here is a [nice article](http://python.net/%7Egoodger/projects/pycon/2007/idiomatic/handout.html#other-languages-have-variables) explaining it using \"boxes\" (for people with C background) and \"name tags\" (in the case of Python):"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user