class Person:
height=180 #类属性,是实例共享的,成员共享
name='王宝强'
count=0
def __init__(self,name,height):
#height是形参
# print('i am a person object')
# return 'hehe' 必须返回的是空值
self.height=height #实例的属性,相当于person.height=150
self.name=name #self表示当前实例的意思,实例变量
__class__.count+=1 #类名Person可以换成__class__
print('我是第'+str(__class__.count)+'实例,我叫'+self.n
def say(self):
print('i am '+self.name)#前面加__表示属性是私有的
# return 'hahah'
#封装,我安装了一些检查规则
def getheight(self):
#权限校验
return self.__height
def setheight(self,height):
#检查入口参数的合法性
self.__height=height
@classmethod #装饰器,可以调用实例
def classCount(cls):
print('一共 '+str(cls.count)+'个对')
# Person.classSay()
person1=Person('堂七七',150)
person2=Person('堂七七',150)
# person.setheight(175) #可以通过外部实例化修改之前的属性值
# print(person.height)
#对象的三个特征 值 id 类型
# == id() typr()
peoson(id(person1)
peoson(id(person2)
peoson(person1 is person2)