python class in __next__ usage

class A (): 
DEF the __init __ (Self, B):
self.b, = B
# DEF the __iter __ (Self): # This function can be used to indicate the iteration flag, may be omitted
# return Self
DEF the __next __ (Self):
IF Self .B <10:
self.b, + 2 = self.b,
the else:
The raise the StopIteration
self.d self.b, + 10 =
return self.d
DEF K (Self):
self.b, = 500 * self.b,
return self.b,
A = C (2)
for I in Range (. 4):
Print (C .__ Next __ ()) # can be iterated this, it is possible to use loop statement
print (cK ()) # can not iterative, it is not used loop

 

Guess you like

Origin www.cnblogs.com/tangjunjun/p/11490638.html