zoukankan      html  css  js  c++  java
  • 2019年7月4日 类与对象1

    d1=类名()  实例化

    python2 中 分经典类和新式类

    python3 中 只有新式类

    属性:

      1.数据属性——变量

      2.函数属性,就是函数,面向对象通常称为方法

      类和对象均用点来方法

    class Chinese:
        'chinese people 的类'
        dang='GCD' #定义来属性
        def sui_di_tu_tan():#将自身传递给参数
            print('随地吐痰')
        def cha_dui(self):
            print('插到了前面')
    
    
    print(Chinese.dang) #调用类
    print(Chinese.__dict__) #查看类的属性字典
    Chinese.sui_di_tu_tan()
    print(Chinese.__dict__['dang'])#通过字典方式寻找属性
    Chinese.__dict__['sui_di_tu_tan']()#通过字典方式寻找属性,函数属性+括号
    Chinese.cha_dui('xxxx') #如果由self 则必须要传递个对象
    p1=Chinese() #加括号 则称为实例化,本质同return

    》》》

    GCD
    {'__module__': '__main__', '__doc__': 'chinese people 的类', 'dang': 'GCD', 'sui_di_tu_tan': <function Chinese.sui_di_tu_tan at 0x100768f28>, 'cha_dui': <function Chinese.cha_dui at 0x100768e18>, '__dict__': <attribute '__dict__' of 'Chinese' objects>, '__weakref__': <attribute '__weakref__' of 'Chinese' objects>}
    随地吐痰
    GCD
    随地吐痰
    插到了前面

  • 相关阅读:
    九.Protobuf3特殊类型
    八.Protobuf3更新消息类型(添加新的字段)
    七.Protobuf3 嵌套类型
    六.Protobuf3引入其他.proto文件
    五.Protobuf3 枚举
    四.Protobuf3 缺省值
    VC 在调用main函数之前的操作
    Windows下的代码注入
    C 堆内存管理
    VC++ 崩溃处理以及打印调用堆栈
  • 原文地址:https://www.cnblogs.com/python1988/p/11129236.html
Copyright © 2011-2022 走看看