Skip to content

Commit e36c462

Browse files
committed
Update slides.
1 parent 743d2dd commit e36c462

File tree

1 file changed

+51
-96
lines changed

1 file changed

+51
-96
lines changed

slides.ipynb

+51-96
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,10 @@
2525
}
2626
},
2727
"source": [
28-
"# Terminology"
29-
]
30-
},
31-
{
32-
"cell_type": "markdown",
33-
"metadata": {
34-
"slideshow": {
35-
"slide_type": "fragment"
36-
}
37-
},
38-
"source": [
39-
"* \"Dunder\" is used to reference \"double underscore\" names."
40-
]
41-
},
42-
{
43-
"cell_type": "markdown",
44-
"metadata": {
45-
"slideshow": {
46-
"slide_type": "fragment"
47-
}
48-
},
49-
"source": [
28+
"# Terminology\n",
29+
"\n",
30+
"* \"Dunder\" is used to reference \"double underscore\" names.\n",
31+
"\n",
5032
"* E.g. `__init__()` is called \"dunder init\"."
5133
]
5234
},
@@ -58,28 +40,12 @@
5840
}
5941
},
6042
"source": [
61-
"# Magic Methods"
62-
]
63-
},
64-
{
65-
"cell_type": "markdown",
66-
"metadata": {
67-
"slideshow": {
68-
"slide_type": "fragment"
69-
}
70-
},
71-
"source": [
72-
"* Beautiful, intuitive, and standard ways of performing basic operations."
73-
]
74-
},
75-
{
76-
"cell_type": "markdown",
77-
"metadata": {
78-
"slideshow": {
79-
"slide_type": "fragment"
80-
}
81-
},
82-
"source": [
43+
"# Magic Methods\n",
44+
"\n",
45+
"* Special methods with reserved names.\n",
46+
"\n",
47+
"* Beautiful, intuitive, and standard ways of performing basic operations.\n",
48+
"\n",
8349
"* Define meaning for operators so that we can use them on our own classes like they were built in types."
8450
]
8551
},
@@ -163,7 +129,7 @@
163129
},
164130
"outputs": [],
165131
"source": [
166-
"(2).__pow__(3) "
132+
"(2).__pow__(3) "
167133
]
168134
},
169135
{
@@ -188,51 +154,15 @@
188154
}
189155
},
190156
"source": [
191-
"# What about our own custom objects?"
192-
]
193-
},
194-
{
195-
"cell_type": "markdown",
196-
"metadata": {
197-
"slideshow": {
198-
"slide_type": "fragment"
199-
}
200-
},
201-
"source": [
202-
"* We can add magic methods to make our own objects behave like built-in types."
203-
]
204-
},
205-
{
206-
"cell_type": "markdown",
207-
"metadata": {
208-
"slideshow": {
209-
"slide_type": "fragment"
210-
}
211-
},
212-
"source": [
213-
"* Why would we do that?"
214-
]
215-
},
216-
{
217-
"cell_type": "markdown",
218-
"metadata": {
219-
"slideshow": {
220-
"slide_type": "fragment"
221-
}
222-
},
223-
"source": [
224-
"* Expressiveness!"
225-
]
226-
},
227-
{
228-
"cell_type": "markdown",
229-
"metadata": {
230-
"slideshow": {
231-
"slide_type": "fragment"
232-
}
233-
},
234-
"source": [
235-
"* ...and it's zen."
157+
"# What about our own custom objects?\n",
158+
"\n",
159+
"* We can add magic methods to make our own objects behave like built-in types.\n",
160+
"\n",
161+
"* Why would we do that?\n",
162+
"\n",
163+
"* Expressiveness!\n",
164+
"\n",
165+
"* It is Zen."
236166
]
237167
},
238168
{
@@ -441,6 +371,31 @@
441371
"### This is why!"
442372
]
443373
},
374+
{
375+
"cell_type": "markdown",
376+
"metadata": {
377+
"slideshow": {
378+
"slide_type": "fragment"
379+
}
380+
},
381+
"source": [
382+
"The identity operator `is` returns true only if the `id()` function on both objects is equal."
383+
]
384+
},
385+
{
386+
"cell_type": "code",
387+
"execution_count": null,
388+
"metadata": {
389+
"collapsed": false,
390+
"slideshow": {
391+
"slide_type": "fragment"
392+
}
393+
},
394+
"outputs": [],
395+
"source": [
396+
"hex(id(slc1)), hex(id(slc2)) "
397+
]
398+
},
444399
{
445400
"cell_type": "code",
446401
"execution_count": null,
@@ -452,7 +407,7 @@
452407
},
453408
"outputs": [],
454409
"source": [
455-
"hex(id(slc1)), hex(id(slc2))"
410+
"slc1 is slc2"
456411
]
457412
},
458413
{
@@ -699,7 +654,7 @@
699654
}
700655
},
701656
"source": [
702-
"# One solution\n",
657+
"# Old and busted\n",
703658
"\n",
704659
"* Create a method to compute distance from the instance to supplied Point instance."
705660
]
@@ -751,7 +706,7 @@
751706
}
752707
},
753708
"source": [
754-
"# The magic solution\n",
709+
"# New hotness\n",
755710
"\n",
756711
"* The `__sub__()` magic method."
757712
]
@@ -926,7 +881,7 @@
926881
}
927882
},
928883
"source": [
929-
"# Point without magic"
884+
"# Old and busted"
930885
]
931886
},
932887
{
@@ -987,7 +942,7 @@
987942
}
988943
},
989944
"source": [
990-
"# Point with magic"
945+
"# New hotness"
991946
]
992947
},
993948
{
@@ -1048,7 +1003,7 @@
10481003
}
10491004
},
10501005
"source": [
1051-
"# Distance with magic"
1006+
"# More new hotness"
10521007
]
10531008
},
10541009
{

0 commit comments

Comments
 (0)