# 面向对象OO
# 类和对象
# 属性和方法
# 继承、封装、
# class ClassDemo: #类名开头必须大写
# '''类的一些说明'''
# pass
#
# '''类的使用——实例化一个类'''
# myclass = ClassDemo()
# myclass1 = ClassDemo()
#
# print(myclass)#打印的是对象 <__main__.ClassDemo object at 0x000002D1A06B6AF0>
# print(myclass1)#打印的拎一个对象,在内存中占用不同的地址 <__main__.ClassDemo object at 0x00000258B4F96AC0>
# print(type(myclass))#对象的类型 <class '__main__.ClassDemo'>
# print(id(myclass)) #对象的地址 3099362814704
# print(hex(id(myclass)))
class Person:#定义类
'''类的说明'''
height=180 #类属性是所有实例共享的
name='赵丽颖'
def __init__(self,name,height):
'''init是构造函数,self是变量名'''
'''什么是函数,什么是方法'''
print('i an a Person object')
self.height=height
self.name=name
'''self为当前实例的意思'''
'''person.__init__() # 手动调用构造函数'''
def say(self):
print('i am speaking'+self.name)
@classmethod
def classSay(cls):
print('一共'+str(cls.height)+cls.name)
'''cls调用的类属性就是大环境下的赵丽颖'''
'''实例属性的私有性'''
person=Person('堂七七',150)
person.say()
person2 = Person('其他他',178)
person2.say()
Person.classSay()
# person = Person() #先实例化
# person1=Person()
# person.say() #再赋予行为
# print(person.say())
# person.height=150
# person1.height=178
# print(person.height)
# print(person1.height)
# print(Person.height)
'''实例属性没有的情况下,会使用同名的类属性'''
# print(person.__dict__)
# print(person1.__dict__)
# print(Person.__dict__)
'''150
178
180'''
i an a Person object
i am speaking堂七七
i an a Person object
i am speaking其他他
一共180赵丽颖