python重载运算符
来源:互联网 发布:1.5厚js防水涂料用量 编辑:程序博客网 时间:2024/06/04 18:41
class Time60(object): 'Time60 - trace hours and minutes' def __init__(self,h,m): 'constructor - takes hours and minutes' self.h=h self.m=m def __str__(self): 'string representation' return "%02d:%02d" % (self.h,self.m) __repe__=__str__ def __add__(self,other): 'overloading the addition operator' m=self.m+other.m h=(self.h+other.h+m//60) return self.__class__(h,m%60) def __iadd__(self,other): 'overloading in-place addition' m=self.m+other.m h=(self.h+other.h+m//60) self.m=m%60 self.h=h; return selffrom random import choiceclass RandSeq(object): def __init__(self,seq): self.data=seq def __iter__(self): return self def __next__(self): return choice(self.data)x=Time60(12,5)print(x)a=RandSeq([1,2,34,45,7,9,5,3,7])it=iter(a)for x in range(5): print(it.__next__())
0 0
- Python运算符重载
- Python运算符重载
- Python运算符重载
- Python运算符重载
- Python运算符重载
- python 重载运算符
- Python运算符重载
- python重载运算符
- python运算符重载
- Python 运算符重载
- Python运算符重载
- Python 运算符重载
- Python运算符重载
- Python-运算符重载
- Python 运算符重载
- [Python]重载运算符
- python运算符重载
- python运算符重载实例
- 【socket】有关socket的编程<三>
- gcc编译器默认支持的c语言标准
- json数据格式
- 【J2SE】对J2SE整体理解
- 进程间通信方式
- python重载运算符
- 机器学习算法之:指数族分布与广义线性模型
- hdu4548 美素数(素数打表)
- (linux命令学习)找到相应性质的文件并删除
- LTE学习:CCE(2)
- Linux export 命令
- u-boot-2009.11移植(适用于TQ2440和MINI2440)第二篇:探索启动代码
- 对象的容纳
- java 性能监控 jstack 线程死锁 JConsole 和 BTrace 图形化工具