类练习题

class Student():

count=5

def init(self,name):

self.name=name

@staticmethod

def hx():

print(‘我只是一个方法,与类和对象没有任何关系’)

@classmethod

def cmethod(cls,cs1,cs2):

print(cls.countcs1cs2)

@staticmethod

def smethod(cs1,cs2):

print(cs1*cs2)

def omethod(self,n):

print(self.name*n)

s=Student(‘张三’)

Student.cmethod(3,4)

Student.smethod(3,4)

s.omethod(2)

猜你喜欢

转载自blog.csdn.net/YPL_ZML/article/details/88025839