Python __next__ 两方面使用

>>> class A:
	def __iter__(self):
		return self
	def __next__(self):
		return 2

	
>>> class B:
	def __iter__(self):
		return A()
	def __next__(self):
		return 1

	
>>> b = B()
>>> next(b)
1
>>> for i in b:
	print(i)

	
2


 

 

 

展开阅读全文