summaryrefslogtreecommitdiff
path: root/notebooks/python/python_oo.ipynb
diff options
context:
space:
mode:
authorSimeon Simeonov2022-12-06 05:50:53 +0100
committerSimeon Simeonov2022-12-06 05:50:53 +0100
commit6a6d09c488826c5d8e618f3d0a5db9997914b5f5 (patch)
tree9c7e274723075f5bd48a58c4e354196a9b564cbf /notebooks/python/python_oo.ipynb
parent013f97e04556c7c0980d673818a77f40fa7882ca (diff)
Update python/python_3_8_to_3_11.ipynb, python/python_intro.ipynb, python/python_oo.ipynb and sqlalchemy/sqlalchemy.ipynb
Diffstat (limited to 'notebooks/python/python_oo.ipynb')
-rw-r--r--notebooks/python/python_oo.ipynb77
1 files changed, 60 insertions, 17 deletions
diff --git a/notebooks/python/python_oo.ipynb b/notebooks/python/python_oo.ipynb
index fe717a9..7147a87 100644
--- a/notebooks/python/python_oo.ipynb
+++ b/notebooks/python/python_oo.ipynb
@@ -106,7 +106,7 @@
106 "\n", 106 "\n",
107 "- class variable - attribute of which a single copy exists, regardless of how many instances of the class exist\n", 107 "- class variable - attribute of which a single copy exists, regardless of how many instances of the class exist\n",
108 "\n", 108 "\n",
109 "- object / instance variable - attribute for which each instantiated object of the class has a separate copy, or instance\n", 109 "- object / instance variable, object / instance attribute - attribute for which each instantiated object of the class has a separate copy, or instance\n",
110 "\n", 110 "\n",
111 "- method - member function - function that is an attribute" 111 "- method - member function - function that is an attribute"
112 ] 112 ]
@@ -208,7 +208,7 @@
208 }, 208 },
209 { 209 {
210 "cell_type": "code", 210 "cell_type": "code",
211 "execution_count": 70, 211 "execution_count": 1,
212 "id": "391e816e-c53b-454b-9e9f-3587234f1fea", 212 "id": "391e816e-c53b-454b-9e9f-3587234f1fea",
213 "metadata": {}, 213 "metadata": {},
214 "outputs": [ 214 "outputs": [
@@ -241,6 +241,8 @@
241 " initialization of the base class part of the instance;\n", 241 " initialization of the base class part of the instance;\n",
242 " for example: super().__init__([args...]).\n", 242 " for example: super().__init__([args...]).\n",
243 " \"\"\"\n", 243 " \"\"\"\n",
244 " # defines instance attributes that will \"live\" as long as\n",
245 " # the object / instance \"lives\" \n",
244 " self._x = x # _ indicates \"protected\" attribute\n", 246 " self._x = x # _ indicates \"protected\" attribute\n",
245 " self.__y = y # not a typo: __ indicates \"private\" attribute.\n", 247 " self.__y = y # not a typo: __ indicates \"private\" attribute.\n",
246 "\n", 248 "\n",
@@ -306,7 +308,7 @@
306 }, 308 },
307 { 309 {
308 "cell_type": "code", 310 "cell_type": "code",
309 "execution_count": 71, 311 "execution_count": 2,
310 "id": "e82feefb-025d-4cbb-a8ac-ddc3cc01269c", 312 "id": "e82feefb-025d-4cbb-a8ac-ddc3cc01269c",
311 "metadata": {}, 313 "metadata": {},
312 "outputs": [ 314 "outputs": [
@@ -389,7 +391,7 @@
389 }, 391 },
390 { 392 {
391 "cell_type": "code", 393 "cell_type": "code",
392 "execution_count": 72, 394 "execution_count": 3,
393 "id": "71a90ec6-3cc0-441e-a866-c2c2b9984559", 395 "id": "71a90ec6-3cc0-441e-a866-c2c2b9984559",
394 "metadata": {}, 396 "metadata": {},
395 "outputs": [ 397 "outputs": [
@@ -503,7 +505,7 @@
503 }, 505 },
504 { 506 {
505 "cell_type": "code", 507 "cell_type": "code",
506 "execution_count": 73, 508 "execution_count": 4,
507 "id": "a4d2735d-d167-4f43-ad55-cb3d13ece2dc", 509 "id": "a4d2735d-d167-4f43-ad55-cb3d13ece2dc",
508 "metadata": {}, 510 "metadata": {},
509 "outputs": [ 511 "outputs": [
@@ -546,7 +548,7 @@
546 }, 548 },
547 { 549 {
548 "cell_type": "code", 550 "cell_type": "code",
549 "execution_count": 74, 551 "execution_count": 5,
550 "id": "a6ead5e6-e987-4bda-bf48-30f91877278d", 552 "id": "a6ead5e6-e987-4bda-bf48-30f91877278d",
551 "metadata": {}, 553 "metadata": {},
552 "outputs": [ 554 "outputs": [
@@ -605,7 +607,7 @@
605 }, 607 },
606 { 608 {
607 "cell_type": "code", 609 "cell_type": "code",
608 "execution_count": 75, 610 "execution_count": 6,
609 "id": "11f6a3fb-64d7-40a9-a130-27548ec4b802", 611 "id": "11f6a3fb-64d7-40a9-a130-27548ec4b802",
610 "metadata": {}, 612 "metadata": {},
611 "outputs": [ 613 "outputs": [
@@ -683,7 +685,7 @@
683 }, 685 },
684 { 686 {
685 "cell_type": "code", 687 "cell_type": "code",
686 "execution_count": 76, 688 "execution_count": 7,
687 "id": "c345a69f-02da-40e7-bb37-c0511b6af096", 689 "id": "c345a69f-02da-40e7-bb37-c0511b6af096",
688 "metadata": {}, 690 "metadata": {},
689 "outputs": [ 691 "outputs": [
@@ -774,7 +776,7 @@
774 }, 776 },
775 { 777 {
776 "cell_type": "code", 778 "cell_type": "code",
777 "execution_count": 77, 779 "execution_count": 8,
778 "id": "44d47e1c-1a06-4577-8db6-6ec78ce5cef8", 780 "id": "44d47e1c-1a06-4577-8db6-6ec78ce5cef8",
779 "metadata": {}, 781 "metadata": {},
780 "outputs": [ 782 "outputs": [
@@ -948,7 +950,7 @@
948 }, 950 },
949 { 951 {
950 "cell_type": "code", 952 "cell_type": "code",
951 "execution_count": 78, 953 "execution_count": 9,
952 "id": "e6076925-75f0-456c-aed5-7db0a24a67a1", 954 "id": "e6076925-75f0-456c-aed5-7db0a24a67a1",
953 "metadata": {}, 955 "metadata": {},
954 "outputs": [ 956 "outputs": [
@@ -1059,7 +1061,7 @@
1059 }, 1061 },
1060 { 1062 {
1061 "cell_type": "code", 1063 "cell_type": "code",
1062 "execution_count": 79, 1064 "execution_count": 13,
1063 "id": "cf79617a-95d2-48f2-be66-fa1fa34e4e04", 1065 "id": "cf79617a-95d2-48f2-be66-fa1fa34e4e04",
1064 "metadata": {}, 1066 "metadata": {},
1065 "outputs": [ 1067 "outputs": [
@@ -1067,7 +1069,30 @@
1067 "name": "stdout", 1069 "name": "stdout",
1068 "output_type": "stream", 1070 "output_type": "stream",
1069 "text": [ 1071 "text": [
1070 "Simeon's MRO: (<class '__main__.Simeon'>, <class '__main__.Mother'>, <class '__main__.Grandmother1'>, <class '__main__.Grandfather1'>, <class '__main__.Father'>, <class '__main__.Grandmother2'>, <class '__main__.Grandfather2'>, <class '__main__.Adam'>, <class '__main__.Eve'>, <class 'object'>)\n" 1072 "Simeon's MRO: (<class '__main__.Simeon'>, <class '__main__.Mother'>, <class '__main__.Grandmother1'>, <class '__main__.Grandfather1'>, <class '__main__.Father'>, <class '__main__.Grandmother2'>, <class '__main__.Grandfather2'>, <class '__main__.Adam'>, <class '__main__.Eve'>, <class 'object'>)\n",
1073 "Help on Simeon in module __main__ object:\n",
1074 "\n",
1075 "class Simeon(Mother, Father)\n",
1076 " | Method resolution order:\n",
1077 " | Simeon\n",
1078 " | Mother\n",
1079 " | Grandmother1\n",
1080 " | Grandfather1\n",
1081 " | Father\n",
1082 " | Grandmother2\n",
1083 " | Grandfather2\n",
1084 " | Adam\n",
1085 " | Eve\n",
1086 " | builtins.object\n",
1087 " | \n",
1088 " | Data descriptors inherited from Adam:\n",
1089 " | \n",
1090 " | __dict__\n",
1091 " | dictionary for instance variables (if defined)\n",
1092 " | \n",
1093 " | __weakref__\n",
1094 " | list of weak references to the object (if defined)\n",
1095 "\n"
1071 ] 1096 ]
1072 } 1097 }
1073 ], 1098 ],
@@ -1108,12 +1133,14 @@
1108 " pass\n", 1133 " pass\n",
1109 "\n", 1134 "\n",
1110 "\n", 1135 "\n",
1111 "print(f\"Simeon's MRO: {Simeon.__mro__}\")" 1136 "print(f\"Simeon's MRO: {Simeon.__mro__}\")\n",
1137 "simeon = Simeon()\n",
1138 "help(simeon)"
1112 ] 1139 ]
1113 }, 1140 },
1114 { 1141 {
1115 "cell_type": "code", 1142 "cell_type": "code",
1116 "execution_count": 80, 1143 "execution_count": 11,
1117 "id": "95a1d0cc-0006-4ddc-b08d-d0b8b02acfba", 1144 "id": "95a1d0cc-0006-4ddc-b08d-d0b8b02acfba",
1118 "metadata": {}, 1145 "metadata": {},
1119 "outputs": [ 1146 "outputs": [
@@ -1179,7 +1206,7 @@
1179 }, 1206 },
1180 { 1207 {
1181 "cell_type": "code", 1208 "cell_type": "code",
1182 "execution_count": 81, 1209 "execution_count": 12,
1183 "id": "38066107-0190-4383-ba14-a4e9cd454a9c", 1210 "id": "38066107-0190-4383-ba14-a4e9cd454a9c",
1184 "metadata": {}, 1211 "metadata": {},
1185 "outputs": [ 1212 "outputs": [
@@ -1189,7 +1216,23 @@
1189 "text": [ 1216 "text": [
1190 "Using mock data\n", 1217 "Using mock data\n",
1191 "Extracting production plans from data\n", 1218 "Extracting production plans from data\n",
1192 "some magic is happening here...\n", 1219 "some magic is happening here...\n"
1220 ]
1221 },
1222 {
1223 "data": {
1224 "text/plain": [
1225 "'{}'"
1226 ]
1227 },
1228 "execution_count": 12,
1229 "metadata": {},
1230 "output_type": "execute_result"
1231 },
1232 {
1233 "name": "stdout",
1234 "output_type": "stream",
1235 "text": [
1193 "(<class '__main__.MockedButStillCoolTSPreprocessor'>, <class '__main__.CoolTSPreprocessor'>, <class '__main__.MockConnectionManager'>, <class '__main__.ConnectionManager'>, <class 'object'>)\n" 1236 "(<class '__main__.MockedButStillCoolTSPreprocessor'>, <class '__main__.CoolTSPreprocessor'>, <class '__main__.MockConnectionManager'>, <class '__main__.ConnectionManager'>, <class 'object'>)\n"
1194 ] 1237 ]
1195 } 1238 }
@@ -1248,7 +1291,7 @@
1248 "name": "python", 1291 "name": "python",
1249 "nbconvert_exporter": "python", 1292 "nbconvert_exporter": "python",
1250 "pygments_lexer": "ipython3", 1293 "pygments_lexer": "ipython3",
1251 "version": "3.11.0" 1294 "version": "3.10.8"
1252 } 1295 }
1253 }, 1296 },
1254 "nbformat": 4, 1297 "nbformat": 4,