python的运算符重载
来源:互联网 发布:花生壳免费域名官网 编辑:程序博客网 时间:2024/06/05 09:21
运算符重载调用的方法:
Method Overloads Call for__init__ 构造函数 X=Class()__del__ 析构函数 对象销毁__add__ + X+Y,X+=Y__or__ | X|Y,X|=Y__repr__ 打印转换 print X,repr(X)__str__ 打印转换 print X,str(X)__call__ 调用函数 X()__getattr_ 限制 X.undefine__setattr__ 取值 X.any=value__getitem__ 索引 X[key], For If__len__ 长度 len(X)__cmp__ 比较 X==Y,X<Y__lt__ 小于 X<Y__eq__ 等于 X=Y__radd__ Right-Side + +X__iadd__ += X+=Y__iter__ 迭代 For In
减法重载:
class Number: def __init__(self, start): self.data = start print "self.data = ", self.data def __sub__(self, other): print "other = ", other return Number(self.data - other)number = Number(20)y = number - 10print "y.data = ", y.data输出:
self.data = 20other = 10self.data = 10y.data = 10
...
- python的运算符重载
- python的运算符重载
- Python运算符重载
- Python运算符重载
- Python运算符重载
- Python运算符重载
- Python运算符重载
- python 重载运算符
- Python运算符重载
- python重载运算符
- python运算符重载
- Python 运算符重载
- Python运算符重载
- Python 运算符重载
- Python运算符重载
- Python-运算符重载
- Python 运算符重载
- [Python]重载运算符
- python连接mysql 报'latin-1' codec can't encode character解决方法
- 如何在Mac OS X Lion(10.7) 中读写 NTFS 分区格式
- QT QTableWidget 用法总结
- 《CSS权威指南》笔记--转自博客园
- 关于c中volatile关键字(转贴)
- python的运算符重载
- Android WebView
- comboBox.SelectedItem与SelectedText区别
- c#连接数据库MS SQL Server
- XSL对象格式使用指南(一)
- Android中资源文件的详解和android中的单位介绍
- XSL对象格式使用指南(二)
- 令Ubuntu开机直接进入控制台,不启动x window
- QT操作Excel调用SaveAs保存成2003格式