Skip to content

Commit 419b65a

Browse files
committed
update classes, objects and singleton
1 parent 65d47fc commit 419b65a

File tree

1 file changed

+54
-10
lines changed

1 file changed

+54
-10
lines changed

notebooks/ClassesObjects-Singleton.ipynb

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -872,10 +872,18 @@
872872
"id": "0bc19c94",
873873
"metadata": {},
874874
"source": [
875-
"## Types of Class Methods\n",
875+
"## Types of Class members\n",
876+
"\n",
877+
"- Methods and properties are the two main types of class members\n",
878+
"\n",
879+
"## Types of Class Properties and Methods\n",
880+
"\n",
881+
"### Class Properties\n",
882+
"- class variables that are shared across all the instances of a class\n",
883+
"- attached to the class itself and not to any instance\n",
884+
"- accessed via class name or instance name\n",
885+
"- see example below\n",
876886
"\n",
877-
"- functions are normally called methods within a class\n",
878-
"- see this resource: https://realpython.com/instance-class-and-static-methods-demystified/\n",
879887
"\n",
880888
"### Instance Properties\n",
881889
"\n",
@@ -886,6 +894,9 @@
886894
"- used as attribues/variables\n",
887895
"- see example above\n",
888896
"\n",
897+
"- functions are normally called methods within a class\n",
898+
"- see this resource: https://realpython.com/instance-class-and-static-methods-demystified/\n",
899+
"\n",
889900
"### Instance Methods\n",
890901
" \n",
891902
"- regular *instance method*\n",
@@ -913,7 +924,7 @@
913924
},
914925
{
915926
"cell_type": "code",
916-
"execution_count": null,
927+
"execution_count": 7,
917928
"id": "e4a91bd1",
918929
"metadata": {},
919930
"outputs": [],
@@ -944,32 +955,65 @@
944955
},
945956
{
946957
"cell_type": "code",
947-
"execution_count": null,
958+
"execution_count": 6,
948959
"id": "132ecac5",
949960
"metadata": {},
950-
"outputs": [],
961+
"outputs": [
962+
{
963+
"data": {
964+
"text/plain": [
965+
"('instance method called', <__main__.MyClass at 0x1085c30a0>, 105)"
966+
]
967+
},
968+
"execution_count": 6,
969+
"metadata": {},
970+
"output_type": "execute_result"
971+
}
972+
],
951973
"source": [
952974
"instance = MyClass()\n",
953975
"instance.set_method(2, 3)"
954976
]
955977
},
956978
{
957979
"cell_type": "code",
958-
"execution_count": null,
980+
"execution_count": 3,
959981
"id": "aeca739a",
960982
"metadata": {},
961-
"outputs": [],
983+
"outputs": [
984+
{
985+
"data": {
986+
"text/plain": [
987+
"('class method called', __main__.MyClass, 18)"
988+
]
989+
},
990+
"execution_count": 3,
991+
"metadata": {},
992+
"output_type": "execute_result"
993+
}
994+
],
962995
"source": [
963996
"# call class method\n",
964997
"MyClass.classmethod(3, 5)"
965998
]
966999
},
9671000
{
9681001
"cell_type": "code",
969-
"execution_count": null,
1002+
"execution_count": 4,
9701003
"id": "961ace48",
9711004
"metadata": {},
972-
"outputs": [],
1005+
"outputs": [
1006+
{
1007+
"data": {
1008+
"text/plain": [
1009+
"('static method called', 18)"
1010+
]
1011+
},
1012+
"execution_count": 4,
1013+
"metadata": {},
1014+
"output_type": "execute_result"
1015+
}
1016+
],
9731017
"source": [
9741018
"# call static method\n",
9751019
"MyClass.staticmethod(3, 5)"

0 commit comments

Comments
 (0)