class People(): peoCount = 0 # 类属性 def __init__(self,name,age): # 实例属性 self.__name = name self.__age = age People.peoCount += 1 def getProperty(self): # 定义实例方法 return self.__dict__ @classmethod #定义类方法 def getPeoCount(cls): return cls.peoCount @staticmethod # 定义静态方法 def peoInvalid(**kwargs): print(kwargs) if kwargs["age"] < 18: return False else: return True peo = People("张三",22) peo1 = People("李四",23) print(peo.getProperty()) print(People.getPeoCount()) peoInfo = {'name':'王五','age':17} People.peoInvalid(**peoInfo)
标签:return,name,People,python,age,实例,self,属性 From: https://www.cnblogs.com/liyuanhong/p/18106814