python的iterator object,pythoniterator,class Square
文章由Byrx.net分享于2019-03-23 07:03:15
python的iterator object,pythoniterator,class Square
class Squares: def __init__(self, start, stop): self.value = start - 1 self.stop = stop def __iter__(self): # get iterator object return self def next(self): # on each for iteration if self.value == self.stop: raise StopIteration self.value += 1 return self.value ** 2for i in Squares(1,5): print i,X = Squares(1,5)X = Squares(1,5)print [n for n in X] # exhausts itemsprint [n for n in X] # now it's emptyprint [n for n in Squares(1,5)]print list(Squares(1,3))
相关内容
- python获得系统中所有的挂载点,python获得系统挂载,#
- Class method: __init__ and __call__,__init___call_,class Prod:
- Python调用system命令,python调用system,import osos.
- python http上传文件处理示例,python上传文件,<HTML>
- 动态修改python的系统路径,动态python路径,import syssy
- python判断字符串中是否包含某个字符,python字符串,my
- python抽象类定义,python抽象定义,class Animal
- Add a class member variable on the fly,membervariable,class C1:
- Python多继承,Python继承,class A :
- Python日志类Logger使用示例,pythonlogger,import timec
评论关闭