a=['a',2,3,4,5]
print type(a)
b=iter(a)
print type(b)
print b.next()
C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/bbb/a3.py
<type 'list'>
<type 'listiterator'>
a
a=['a',2,3,4,5]
print type(a)
b=iter(a)
print type(b)
print b.next()
print '-----------------'
print a.__str__()
C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/bbb/a3.py
<type 'list'>
<type 'listiterator'>
a
-----------------
['a', 2, 3, 4, 5]
a=['a',2,3,4,5]
print type(a)
b=iter(a)
print type(b)
print b.next()
print '-----------------'
print a.__iter__()
C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/bbb/a3.py
<type 'list'>
<type 'listiterator'>
a
-----------------
<listiterator object at 0x025D72F0>
class MyIterator(object):
def __init__(self,step):
self.step = step
def next(self):
if self.step == 0:
raise StopIteration
self.step -= 1
return self.step
def __iter__(self):
return self
# for e1 in MyIterator(4):
# print e1
a=MyIterator(4)
print a
print type(a)
print a.next()
print a.next()
print a.next()
C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/bbb/a4.py
<__main__.MyIterator object at 0x025B7330>
<class '__main__.MyIterator'>
3
2
1