Skip to content

Commit 87b1560

Browse files
committed
Inheritance
1 parent 7036b34 commit 87b1560

File tree

1 file changed

+259
-0
lines changed

1 file changed

+259
-0
lines changed

Diff for: 13.Inheritance.ipynb

+259
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,265 @@
9797
"t.findArea()"
9898
]
9999
},
100+
{
101+
"cell_type": "code",
102+
"execution_count": 7,
103+
"metadata": {},
104+
"outputs": [
105+
{
106+
"data": {
107+
"text/plain": [
108+
"True"
109+
]
110+
},
111+
"execution_count": 7,
112+
"metadata": {},
113+
"output_type": "execute_result"
114+
}
115+
],
116+
"source": [
117+
"isinstance(t,Triangle)"
118+
]
119+
},
120+
{
121+
"cell_type": "code",
122+
"execution_count": 8,
123+
"metadata": {},
124+
"outputs": [
125+
{
126+
"data": {
127+
"text/plain": [
128+
"True"
129+
]
130+
},
131+
"execution_count": 8,
132+
"metadata": {},
133+
"output_type": "execute_result"
134+
}
135+
],
136+
"source": [
137+
"isinstance(t,Polygon)"
138+
]
139+
},
140+
{
141+
"cell_type": "code",
142+
"execution_count": 9,
143+
"metadata": {},
144+
"outputs": [
145+
{
146+
"data": {
147+
"text/plain": [
148+
"False"
149+
]
150+
},
151+
"execution_count": 9,
152+
"metadata": {},
153+
"output_type": "execute_result"
154+
}
155+
],
156+
"source": [
157+
"isinstance(t,int)"
158+
]
159+
},
160+
{
161+
"cell_type": "code",
162+
"execution_count": 10,
163+
"metadata": {},
164+
"outputs": [
165+
{
166+
"data": {
167+
"text/plain": [
168+
"True"
169+
]
170+
},
171+
"execution_count": 10,
172+
"metadata": {},
173+
"output_type": "execute_result"
174+
}
175+
],
176+
"source": [
177+
"isinstance(t,object)"
178+
]
179+
},
180+
{
181+
"cell_type": "code",
182+
"execution_count": 11,
183+
"metadata": {},
184+
"outputs": [
185+
{
186+
"data": {
187+
"text/plain": [
188+
"False"
189+
]
190+
},
191+
"execution_count": 11,
192+
"metadata": {},
193+
"output_type": "execute_result"
194+
}
195+
],
196+
"source": [
197+
"issubclass(Polygon,Triangle)"
198+
]
199+
},
200+
{
201+
"cell_type": "code",
202+
"execution_count": 12,
203+
"metadata": {},
204+
"outputs": [
205+
{
206+
"data": {
207+
"text/plain": [
208+
"True"
209+
]
210+
},
211+
"execution_count": 12,
212+
"metadata": {},
213+
"output_type": "execute_result"
214+
}
215+
],
216+
"source": [
217+
"issubclass(Triangle,Polygon)"
218+
]
219+
},
220+
{
221+
"cell_type": "code",
222+
"execution_count": 13,
223+
"metadata": {},
224+
"outputs": [
225+
{
226+
"data": {
227+
"text/plain": [
228+
"True"
229+
]
230+
},
231+
"execution_count": 13,
232+
"metadata": {},
233+
"output_type": "execute_result"
234+
}
235+
],
236+
"source": [
237+
"issubclass(bool,int)"
238+
]
239+
},
240+
{
241+
"cell_type": "code",
242+
"execution_count": 14,
243+
"metadata": {},
244+
"outputs": [],
245+
"source": [
246+
"class Base1:\n",
247+
" pass\n",
248+
"class Base2:\n",
249+
" pass\n",
250+
"class MultiDerived(Base1, Base2):\n",
251+
" pass"
252+
]
253+
},
254+
{
255+
"cell_type": "code",
256+
"execution_count": 15,
257+
"metadata": {},
258+
"outputs": [],
259+
"source": [
260+
"class Base:\n",
261+
" pass\n",
262+
"class Derived1(Base):\n",
263+
" pass\n",
264+
"class Derived2(Derived1):\n",
265+
" pass"
266+
]
267+
},
268+
{
269+
"cell_type": "code",
270+
"execution_count": 16,
271+
"metadata": {},
272+
"outputs": [
273+
{
274+
"name": "stdout",
275+
"output_type": "stream",
276+
"text": [
277+
"True\n"
278+
]
279+
}
280+
],
281+
"source": [
282+
"print(issubclass(list,object))"
283+
]
284+
},
285+
{
286+
"cell_type": "code",
287+
"execution_count": 17,
288+
"metadata": {},
289+
"outputs": [
290+
{
291+
"name": "stdout",
292+
"output_type": "stream",
293+
"text": [
294+
"True\n"
295+
]
296+
}
297+
],
298+
"source": [
299+
"print(isinstance(5.5,object))"
300+
]
301+
},
302+
{
303+
"cell_type": "code",
304+
"execution_count": 18,
305+
"metadata": {},
306+
"outputs": [
307+
{
308+
"name": "stdout",
309+
"output_type": "stream",
310+
"text": [
311+
"True\n"
312+
]
313+
}
314+
],
315+
"source": [
316+
"print(isinstance(\"Hello\",object))"
317+
]
318+
},
319+
{
320+
"cell_type": "code",
321+
"execution_count": 19,
322+
"metadata": {},
323+
"outputs": [
324+
{
325+
"data": {
326+
"text/plain": [
327+
"(__main__.MultiDerived, __main__.Base1, __main__.Base2, object)"
328+
]
329+
},
330+
"execution_count": 19,
331+
"metadata": {},
332+
"output_type": "execute_result"
333+
}
334+
],
335+
"source": [
336+
" MultiDerived.__mro__"
337+
]
338+
},
339+
{
340+
"cell_type": "code",
341+
"execution_count": 20,
342+
"metadata": {},
343+
"outputs": [
344+
{
345+
"data": {
346+
"text/plain": [
347+
"[__main__.MultiDerived, __main__.Base1, __main__.Base2, object]"
348+
]
349+
},
350+
"execution_count": 20,
351+
"metadata": {},
352+
"output_type": "execute_result"
353+
}
354+
],
355+
"source": [
356+
"MultiDerived.mro()"
357+
]
358+
},
100359
{
101360
"cell_type": "code",
102361
"execution_count": null,

0 commit comments

Comments
 (0)