Python简化类例五:实现链式写法
来源:互联网 发布:楚楚街聊天是什么软件 编辑:程序博客网 时间:2024/06/03 23:02
# -*- coding: utf-8 -*'''前言:这是我自己想出来的方法,我不知道是否有人用过这种写类的方法,我也没想出一个什么样名字来称呼它,反正我叫它简化类之所以称之为简化类,是因为我没办法实现多重继承,但类的基本继承,重写还是实现了的如果有兴趣的朋友请留下您保贵的建议或加我QQ:410177254 或 微信:carmelcarmen,让这个写法能更有创造性一些'''#Python简化类例五:实现链式写法def ClassTest5(): '''链式写法只要是类语言都可以实写,个人比较喜欢,也就顺手尝试一下''' def p() :pass p.x=0 p.y=0 def o():pass def printPos(): print("当前坐标是(%d, %d)"%(p.x,p.y)) def moveLeft(): p.x-=1 printPos() return o o.moveLeft=moveLeft;del moveLeft def moveTop(): p.y+=1 printPos() return o o.moveTop=moveTop;del moveTop def moveRight(): p.x+=1 printPos() return o o.moveRight=moveRight;del moveRight def moveBottom(): p.y-=1 printPos() return o o.moveBottom=moveBottom;del moveBottom return ot5=ClassTest5()t5.moveTop().moveLeft().moveBottom().moveRight()'''打印结果:当前坐标是(0, 1)当前坐标是(-1, 1)当前坐标是(-1, 0)当前坐标是(0, 0)'''
阅读全文
0 0
- Python简化类例五:实现链式写法
- Python简化类例七:单例类的写法
- 【Python】曲线简化算法实现
- Python简化类例四:关于规范化写法的建议
- Python简化类例六:另一种变量赋值取值的写法
- jquery的链式写法
- php链式写法
- jq链式写法浅析
- 飘逸的python - 实现链式调用
- 简化delegate写法
- 简化delegate写法
- Android 简化findViewById写法
- tableView简化写法
- android findviewbyId 简化写法
- 汇编程序的简化写法
- 代码写法讨论:链式处理
- jQuary事件的链式写法
- jQuery事件的链式写法
- ECO生态币官网blog.sina.com.cn/ecocoin
- (OK) Install php 5.6 in fedora-27
- [1126]codeforces灌水总结
- unique_distance
- 疯狂啃的C
- Python简化类例五:实现链式写法
- 引用类型
- Matlab图像处理之均值滤波
- 快速排序二叉树实现思想(个人看到二分法排序想到的)
- LaTeX手动安装宏包(package)以及生成帮助文档的整套流程
- 结构体、位段、枚举、联合
- 在2017年将会更加流行的6个Web开发趋势
- [深度学习]深度学习中卷积操作和数学中卷积操作的异同
- 认识CSS