Update 3.md

This commit is contained in:
IBen
2020-03-08 20:43:09 +08:00
committed by GitHub
parent e35ed125a7
commit 8349428317

View File

@@ -29,12 +29,12 @@ class 就是类method 就是方法。
因此类方法,想要调用类属性,需要以下步骤:
* 在方法上面,用 `@classmethon` 声明该方法是类方法。只有声明了是类方法,才能使用类属性
* 在方法上面,用 `@classmethod` 声明该方法是类方法。只有声明了是类方法,才能使用类属性
* 类方法想要使用类属性,在第一个参数中,需要写上 `cls` , cls 是 class 的缩写,其实意思就是把这个类作为参数,传给自己,这样就可以使用类属性了。
* 类属性的使用方式就是 `cls.变量名`
记住喔,无论是 `@classmethon` 还是 `cls` ,都是不能省去的。
记住喔,无论是 `@classmethod` 还是 `cls` ,都是不能省去的。
省了都会报错。