zoukankan      html  css  js  c++  java
  • 面向对象的类的增删改查(数据属性和函数属性)

    class School:
       
        country = "china"
       def __init__(self,name):
          self.name = name
        def have_lesson(self):
            print("%s的班级正在上课"%self)
    p1 = School("李老师")
    '''类数据属性的增删改查 查 print(School.country)
    >>> china
    改 School.country="japan" print(School.country)
    >>>japan 增 School.foo ="小孙" print(School.__dict__)
    >>>{'country':'japan','foo':'小孙'.........} 删 del School.foo print(School.__dict__)
    ''' #类函数属性的增删改查同实例属性 def eat_food(self,food): print("正在吃") School.eat = eat_food print(School.__dict__) # 的确增加一个eat print(School.eat) # 显示是一个eat的内存地址
    类能不能调用函数属性?

    School.eat('lao_wang','屎')
    >>>>> 正在吃
    School.have_lesson('wang')
    >>>>>wang的班级正在上课
    这里的self只是一个形参, 没有self.name的功能,只有通过init定义的self.name 这个self才是可以用点调用


    类的函数属性删除:
    必须在函数前面写明哪个类下
  • 相关阅读:
    【CF989E】A Trance of Nightfall
    [SHOI2012]信用卡凸包
    [HNOI2016]最小公倍数
    [HNOI2012]射箭
    [SCOI2015]小凸想跑步
    [CQOI2006]凸多边形
    ### Hadoop
    ### awk
    ### Theano
    ### Python Learning
  • 原文地址:https://www.cnblogs.com/vincent-sh/p/12767021.html
Copyright © 2011-2022 走看看