class name:
a = xxxxxx
b = xxxxxx
c = xxxxxx
@classmethod
def name():
xxxxxx
xxxxxx
return xxxxxx
sa = xxxxxx
sb = xxxxxx
sc = xxxxxx
如何运用
class c:
@classmethod
def a(self,num):
num = num * num - 1
c.a(9)
输出:
80
如果不用这段看似没用的代码,就有一个traceback.
@classmethod # 绑定参数
没有参数
class c:
@classmethod
def a():
num = 10 * 10 - 1
c.a()
输出:
traceback:
file stdin.py,line 3 in module,
def a():
^
a was 0 given but 1 was given.
class c:
@classmethod
def a(self):
num = 10 * 10 - 1
c.a()
输出 :
99
下级代码用“.”连接。
小结今天我们知道了python类,还知道了@classmethod方法和参数应用以及下级指令。