Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3d23f6e

Browse files
Add Jupyter notebook demonstrating hybrid inheritance in Python
1 parent 9a54f37 commit 3d23f6e

File tree

2 files changed

+109
-2
lines changed

2 files changed

+109
-2
lines changed

‎00 Lecture/CWPC01/16 Oct 2025/Hierarchical_inheritance.ipynb‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,19 @@
3838
},
3939
{
4040
"cell_type": "code",
41-
"execution_count": null,
41+
"execution_count": 6,
4242
"id": "d9048f1d",
4343
"metadata": {},
44-
"outputs": [],
44+
"outputs": [
45+
{
46+
"name": "stdout",
47+
"output_type": "stream",
48+
"text": [
49+
"this is parent class\n",
50+
"this is parent class\n"
51+
]
52+
}
53+
],
4554
"source": [
4655
"obj1 = child1()\n",
4756
"obj2 = child2()\n",
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 10,
6+
"id": "8cf16ae9",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"class A:\n",
11+
" def showA():\n",
12+
" print(\"class A\")"
13+
]
14+
},
15+
{
16+
"cell_type": "code",
17+
"execution_count": 11,
18+
"id": "83b121ad",
19+
"metadata": {},
20+
"outputs": [],
21+
"source": [
22+
"class B(A):\n",
23+
" def showB():\n",
24+
" print(\"class B\")"
25+
]
26+
},
27+
{
28+
"cell_type": "code",
29+
"execution_count": 12,
30+
"id": "3d42595e",
31+
"metadata": {},
32+
"outputs": [],
33+
"source": [
34+
"class C(A):\n",
35+
" def showC():\n",
36+
" print(\"class C\")"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": 13,
42+
"id": "76992b0f",
43+
"metadata": {},
44+
"outputs": [],
45+
"source": [
46+
"class D(B,C): # inherits from B and C\n",
47+
" def showD():\n",
48+
" print(\"class D\")"
49+
]
50+
},
51+
{
52+
"cell_type": "code",
53+
"execution_count": 15,
54+
"id": "fce855ec",
55+
"metadata": {},
56+
"outputs": [
57+
{
58+
"name": "stdout",
59+
"output_type": "stream",
60+
"text": [
61+
"class A\n",
62+
"class B\n",
63+
"class C\n",
64+
"class D\n"
65+
]
66+
}
67+
],
68+
"source": [
69+
"object = D\n",
70+
"object.showA()\n",
71+
"object.showB()\n",
72+
"object.showC()\n",
73+
"object.showD()"
74+
]
75+
}
76+
],
77+
"metadata": {
78+
"kernelspec": {
79+
"display_name": "Python 3",
80+
"language": "python",
81+
"name": "python3"
82+
},
83+
"language_info": {
84+
"codemirror_mode": {
85+
"name": "ipython",
86+
"version": 3
87+
},
88+
"file_extension": ".py",
89+
"mimetype": "text/x-python",
90+
"name": "python",
91+
"nbconvert_exporter": "python",
92+
"pygments_lexer": "ipython3",
93+
"version": "3.13.7"
94+
}
95+
},
96+
"nbformat": 4,
97+
"nbformat_minor": 5
98+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /