linux:python:使用class变量
差别
这里会显示出您选择的修订版和当前版本之间的差别。
| 两侧同时换到之前的修订记录前一修订版后一修订版 | 前一修订版 | ||
| linux:python:使用class变量 [2020/10/09 22:31] – zhangguo | linux:python:使用class变量 [2026/10/14 06:39] (当前版本) – 外部编辑 127.0.0.1 | ||
|---|---|---|---|
| 行 1: | 行 1: | ||
| - | ====== | + | # python3使用class变量 |
| - | + | ||
| 有些时候可能一些公共的函数需要写成classmethod的方式,即不用把class给先实例化之后再使用,可以直接采用《类名.方法名》的方式使用。 | 有些时候可能一些公共的函数需要写成classmethod的方式,即不用把class给先实例化之后再使用,可以直接采用《类名.方法名》的方式使用。 | ||
| 行 10: | 行 8: | ||
| - class b在class a实例化时进行赋值,之后class a一直以classmethod的方式使用。 | - class b在class a实例化时进行赋值,之后class a一直以classmethod的方式使用。 | ||
| - | - class b的实例化在class a的一个classmethod方法中完成,class a的方法总是以classmethod的方式进行使用。< | + | - class b的实例化在class a的一个classmethod方法中完成,class a的方法总是以classmethod的方式进行使用。< |
| - | < | + | |
| + | ```python | ||
| class b(object): | class b(object): | ||
| def __init__(self, | def __init__(self, | ||
| 行 41: | 行 40: | ||
| a.set_name(' | a.set_name(' | ||
| a.myprint() | a.myprint() | ||
| - | </ | + | ``` |
linux/python/使用class变量.1602253912.txt.gz · 最后更改: (外部编辑)
