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
    随地吐痰
    插到了前面

  • 相关阅读:
    Linux命令(25)userdel命令
    Linux命令(24)clear命令
    Linux命令(23)usermod命令
    Linux命令(22)useradd命令
    c++primer 练习9.28
    概率论python代码
    python自写软件(三)
    Linux描述符表和描述符高速缓存
    操作系统的坑(更新)
    python自写软件(二)
  • 原文地址:https://www.cnblogs.com/python1988/p/11129236.html
Copyright © 2011-2022 走看看