website Explanation:
New in version 2.2.
That is to say, __iter__ and next () are used in support.
Fibonacci Series:
#!/usr/bin/python
#-*-Coding:utf-8-*-
Class Fibo (object):
def __init__ (self):
SELF.A, self.b = 0, 1
def __iter__ (self):
return self
def __next__ (self):
SELF.A, self.b = self.b, SELF.A + self.b
If SELF.A > 10000:
Raise Stopiteration ()
Return SELF.A, self.b
For n in Fibo ():
Print n
Failed to run:
How do you use class to succeed?????
Later, only to find that my 2.7 version of the interpreter is not supported, using the PYTHON3 online programming interpreter on the Web is perfect to run ... is Ri le gou le.
Python3 Environment for use: http://www.dooccn.com/python3/
I would like to ask you guys, in the 2.7 version of how should I use __iter__?? Ask for advice!
Python Class: Object-oriented advanced programming __iter__ and next ()