类的使用

class LuffyStudent:
    school = "Luffycity"  # 数据属性

    def learn(self):  # 函数属性
        print("is Learning")

    def eat(self):  # 函数属性
        print("is eating")

    def sleep(self):
        print("is sleeping")

查看类的名称空间

#查看类的名称空间
print(LuffyStudent.__dict__)
print(LuffyStudent.__dict__["school"])
print(LuffyStudent.__dict__["learn"])

一、查

#
print(LuffyStudent.school)  # 等同于print(LuffyStudent.__dict__["school"])
print(LuffyStudent.learn)

二、增

#
LuffyStudent.county = "China"  # 增加新的变量并赋值
print(LuffyStudent.county)

三、删

#
del LuffyStudent.county

四、改

#
LuffyStudent.school = "Luffycity"
print(LuffyStudent.school)
原文地址:https://www.cnblogs.com/nanjo4373977/p/12166650.html