Skip to content

Commit a305b99

Browse files
committed
mutable objects as default arguments
1 parent 0bab1bb commit a305b99

2 files changed

Lines changed: 118 additions & 2 deletions

File tree

.ipynb_checkpoints/not_so_obvious_python_stuff-checkpoint.ipynb

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"metadata": {
33
"name": "",
4-
"signature": "sha256:0c860c383edcd7622b0c660eb989513e90496c7350916bae1ddb6c10f29fab2c"
4+
"signature": "sha256:611615765638a390c8e9093179758c4a23524ddcc2379aeff80e51c22031aa18"
55
},
66
"nbformat": 3,
77
"nbformat_minor": 0,
@@ -225,6 +225,64 @@
225225
],
226226
"prompt_number": 5
227227
},
228+
{
229+
"cell_type": "markdown",
230+
"metadata": {},
231+
"source": [
232+
"Another popular example to illustrate the reuse of objects for small integers is:"
233+
]
234+
},
235+
{
236+
"cell_type": "code",
237+
"collapsed": false,
238+
"input": [
239+
"print(256 is 257 - 1)\n",
240+
"print(257 is 258 - 1)"
241+
],
242+
"language": "python",
243+
"metadata": {},
244+
"outputs": [
245+
{
246+
"output_type": "stream",
247+
"stream": "stdout",
248+
"text": [
249+
"True\n",
250+
"False\n"
251+
]
252+
}
253+
],
254+
"prompt_number": 2
255+
},
256+
{
257+
"cell_type": "markdown",
258+
"metadata": {},
259+
"source": [
260+
"And to illustrate the test for equality (`==`) vs. identity (`is`):"
261+
]
262+
},
263+
{
264+
"cell_type": "code",
265+
"collapsed": false,
266+
"input": [
267+
"a = 'hello world!'\n",
268+
"b = 'hello world!'\n",
269+
"print('a is b', a is b)\n",
270+
"print('a == b', a == b)"
271+
],
272+
"language": "python",
273+
"metadata": {},
274+
"outputs": [
275+
{
276+
"output_type": "stream",
277+
"stream": "stdout",
278+
"text": [
279+
"a is b False\n",
280+
"a == b True\n"
281+
]
282+
}
283+
],
284+
"prompt_number": 3
285+
},
228286
{
229287
"cell_type": "markdown",
230288
"metadata": {},

not_so_obvious_python_stuff.ipynb

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"metadata": {
33
"name": "",
4-
"signature": "sha256:0c860c383edcd7622b0c660eb989513e90496c7350916bae1ddb6c10f29fab2c"
4+
"signature": "sha256:611615765638a390c8e9093179758c4a23524ddcc2379aeff80e51c22031aa18"
55
},
66
"nbformat": 3,
77
"nbformat_minor": 0,
@@ -225,6 +225,64 @@
225225
],
226226
"prompt_number": 5
227227
},
228+
{
229+
"cell_type": "markdown",
230+
"metadata": {},
231+
"source": [
232+
"Another popular example to illustrate the reuse of objects for small integers is:"
233+
]
234+
},
235+
{
236+
"cell_type": "code",
237+
"collapsed": false,
238+
"input": [
239+
"print(256 is 257 - 1)\n",
240+
"print(257 is 258 - 1)"
241+
],
242+
"language": "python",
243+
"metadata": {},
244+
"outputs": [
245+
{
246+
"output_type": "stream",
247+
"stream": "stdout",
248+
"text": [
249+
"True\n",
250+
"False\n"
251+
]
252+
}
253+
],
254+
"prompt_number": 2
255+
},
256+
{
257+
"cell_type": "markdown",
258+
"metadata": {},
259+
"source": [
260+
"And to illustrate the test for equality (`==`) vs. identity (`is`):"
261+
]
262+
},
263+
{
264+
"cell_type": "code",
265+
"collapsed": false,
266+
"input": [
267+
"a = 'hello world!'\n",
268+
"b = 'hello world!'\n",
269+
"print('a is b', a is b)\n",
270+
"print('a == b', a == b)"
271+
],
272+
"language": "python",
273+
"metadata": {},
274+
"outputs": [
275+
{
276+
"output_type": "stream",
277+
"stream": "stdout",
278+
"text": [
279+
"a is b False\n",
280+
"a == b True\n"
281+
]
282+
}
283+
],
284+
"prompt_number": 3
285+
},
228286
{
229287
"cell_type": "markdown",
230288
"metadata": {},

0 commit comments

Comments
 (0)