python学习之类、对象的属性的增删改查

class Chinese():
    dang = 'gong'

    def gong_fu(self):
        print("太极拳。。。。。。")
        # return self.dang
##类有两种属性
#数据类: 变量
#函数类:方法

###类的
#查看
print(Chinese.dang)
print(Chinese.gong_fu)

#增加
Chinese.guo = "China"
print(Chinese.guo)

def test():
    print("I am test")
Chinese.test = test
Chinese.test()

#改
Chinese.dang = "test"
print(Chinese.dang)

Chinese.gong_fu = test
Chinese.gong_fu()

#删
# del Chinese.dang
# print(Chinese.dang)
#
# del Chinese.gong_fu
# Chinese.gong_fu()

###实例的

#实例只有数据类属性,增删改查同类,调用函数会根据作用域向类中查找


注意事项: 调用类和对象的属性通过“点”,不通过“点”的跟类和对象无关

  

猜你喜欢

转载自www.cnblogs.com/lejie/p/9319402.html