# 1.定义一个类
class Person:
pass
# 2.根据类创建一个对象
# p1 = Person()
# p2 = Person()
# p1.age = 18
# p2.address = "上海"
# print(p1.address) #'Person' object has no attribute 'address'
# 3.给p对向,增加一些属性
# p.age = 18
# print(id(p.age))
# p.hight = 180
# p.age = 123
# print(id(p.age))
# # 4.验证是否添加成功
# print(p.age)
# # print(p.__dict__)
# print(p.sex) # 'Person' object has no attribute 'sex'
# p.pets = ['xiaohua', 'xiaohei']
# print(id(p.pets))
# p.pets.append("xiaohong")
# print(id(p.pets))
# p.pets = ['1', '2']
# print(id(p.pets))
# p.age = 18
# del p.age
# print(p.age)
# class Money:
# pass
# # one = Money()
# # one.age = 18
# Money.count = 1
# Money.age = 18
#
# print(Money.count)
# print(Money.__dict__)
# class Test:
# sex = "男"
class Money:
age = 18
count = 1
num = 666
# Money.age = 22
# print(Money.age) # 属性存在就是修改,不存在就是增加
one = Money()
# del Money.age # AttributeError: type object 'Money' has no attribute 'age'
del one.age # AttributeError: age
# print(Money.age)
print(one.age)
# print(Money.age)
#
# one.age = 19 # 不能通过对向修改
# print(one.age)
# print(Money.count)
# print(Money.age)
# print(Money.num)
# print(Money.__dict__)
# one = Money()
# one.__class__ = Test
# one.sex = "女" # 优先从自己身上找
# print(one.__class__)
#
# print(one.sex)
# print(one.age)
# print(one.count)
# print(one.num)
class Money:
age = 18
name = "sz"
# Money.__dict__ = {"sex": "男"} # AttributeError: attribute '__dict__' of 'type' objects is not writable
print(Money.__dict__)
# Money.__dict__["age"] = 20 # TypeError: 'mappingproxy' object does not support item assignment
one = Money()
one.age = 18
one.height = 180
#
# print(one.__dict__)
# print(Money.__dict__)
# one.__dict__ = {"name": "sz", "age": 18}
one.__dict__["age"] = 999
print(one.name)
# class Person:
# age = 10
# pass
# Person.age = 19
# Person.age = 11
# del Person.age
# Person.age
# p = Person()
# p.age += 5
#
# print(Person.age)
# print(p.age)
class Person():
__slots__ = ["age"]
pass
p1 = Person()
p1.age = 1
p2.age = 2