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

  • 相关阅读:
    事务处理语言(TCL)
    SQL,T-SQL简介
    centos 8 集群Linux环境搭建
    graphviz 的使用教程
    pyttsx3 的使用教程
    python 连接 SQL Server 数据库(使用 pymssql 库)
    python 连接 SQL Server 数据库(使用 pyodbc 库)
    C++注释规范
    IP分配及网段划分
    关于对象的浅度拷贝和深度拷贝
  • 原文地址:https://www.cnblogs.com/python1988/p/11129236.html
Copyright © 2020-2023  润新知