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)

相关文章:

  • 2021-09-30
  • 2021-06-29
  • 2021-11-28
  • 2021-07-23
  • 2021-09-19
  • 2021-04-02
  • 2021-09-13
猜你喜欢
  • 2021-12-27
  • 2021-10-12
  • 2021-06-08
  • 2021-11-10
  • 2021-08-29
相关资源
相似解决方案