首页 > 其他 > 详细

2019年7月4日 类与对象1

时间:2019-07-03 22:31:18      阅读:101      评论:0      收藏:0      [点我收藏+]

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

2019年7月4日 类与对象1

原文:https://www.cnblogs.com/python1988/p/11129236.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!