python操作符重写,实现+操作符,python操作符,import strin
文章由Byrx.net分享于2019-03-23 05:03:09
python操作符重写,实现+操作符,python操作符,import strin
import stringclass spam: def __init__(self): self.eggs = 1 def __del__(self): pass def __add__(self,other): rt = spam() rt.eggs = self.eggs + other.eggs return rt def __coerce__(self,other): rt = spam() if type(other) == type(rt): return (self,other) elif type(other) == type(''): e = string.atoi(other) rt.eggs = e return(self,rt) else: return None def __radd__(self,other): return self + otherif __name__ == '__main__': a = spam() b = spam() a = a + b print 'a now has', a.eggs, 'eggs' a = a + '24' print 'a now has', a.eggs, 'eggs' a = '24' + a print 'a now has', a.eggs, 'eggs'
相关内容
- python中的虚函数,python函数,class Super:
- 抓取知乎日报内容在本地另存为txt文档,日报txt,#File
- 最美应用爬虫,应用爬虫,import reque
- 获取网页上图片的下载地址,获取图片下载地址,#!/us
- python和bash统计CPU利用率,pythonbash利用率,#!/usr/bin/p
- python 爬小说我梦见了欲望,,import urlli
- 多任务多线程任务管理类,多任务多线程管理类,#codi
- 每行数据重复N次合并生成新文件,数据重复n合并,""
- Python用户定义类实现,python用户定义,class Worker
- Python模拟http get,python模拟get,import sys,
评论关闭