hoge.py
class hoge(object):
ham = 0
def __init__(self):
self.spam = 0
def print(self):
print('class.ham ' + str(hoge.ham))
print('self.ham '+ str(self.ham) )
print('self.spam ' + str(self.spam))
self.clsM()#Class method is self.Can be called from
def increment(self):
self.spam += 1
self.ham += 1 #Image that is incremented after being assigned to the class variable ham → instance variable ham
@classmethod
def clsM(cls):
print('called class method')
a = hoge()
a.increment()
a.print()
python
class.ham 5
self.ham 6
self.spam 1
called class method
Recommended Posts