|
872 | 872 | "id": "0bc19c94", |
873 | 873 | "metadata": {}, |
874 | 874 | "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", |
876 | 886 | "\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", |
879 | 887 | "\n", |
880 | 888 | "### Instance Properties\n", |
881 | 889 | "\n", |
|
886 | 894 | "- used as attribues/variables\n", |
887 | 895 | "- see example above\n", |
888 | 896 | "\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", |
889 | 900 | "### Instance Methods\n", |
890 | 901 | " \n", |
891 | 902 | "- regular *instance method*\n", |
|
913 | 924 | }, |
914 | 925 | { |
915 | 926 | "cell_type": "code", |
916 | | - "execution_count": null, |
| 927 | + "execution_count": 7, |
917 | 928 | "id": "e4a91bd1", |
918 | 929 | "metadata": {}, |
919 | 930 | "outputs": [], |
|
944 | 955 | }, |
945 | 956 | { |
946 | 957 | "cell_type": "code", |
947 | | - "execution_count": null, |
| 958 | + "execution_count": 6, |
948 | 959 | "id": "132ecac5", |
949 | 960 | "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 | + ], |
951 | 973 | "source": [ |
952 | 974 | "instance = MyClass()\n", |
953 | 975 | "instance.set_method(2, 3)" |
954 | 976 | ] |
955 | 977 | }, |
956 | 978 | { |
957 | 979 | "cell_type": "code", |
958 | | - "execution_count": null, |
| 980 | + "execution_count": 3, |
959 | 981 | "id": "aeca739a", |
960 | 982 | "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 | + ], |
962 | 995 | "source": [ |
963 | 996 | "# call class method\n", |
964 | 997 | "MyClass.classmethod(3, 5)" |
965 | 998 | ] |
966 | 999 | }, |
967 | 1000 | { |
968 | 1001 | "cell_type": "code", |
969 | | - "execution_count": null, |
| 1002 | + "execution_count": 4, |
970 | 1003 | "id": "961ace48", |
971 | 1004 | "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 | + ], |
973 | 1017 | "source": [ |
974 | 1018 | "# call static method\n", |
975 | 1019 | "MyClass.staticmethod(3, 5)" |
|
0 commit comments