pyton_iterator_learning

 

 

# author: Roy.G
# from collections import iterable
from collections.abc import Iterable,Iterator
a=[1,2,3]
print(isinstance(a,Iterable)) #determine if a subject is iterable
print(isinstance("abc",Iterable))
print(isinstance("abc",Iterator))
print("generator==>",isinstance((x for x in range(3)),Iterator))
print("list==>",isinstance([x for x in range(3)],Iterator))
print([x for x in range(3)],type([x for x in range(3)]))
print((x for x in range(3)),type((x for x in range(3))))
b=iter(a)
print("a==>",isinstance(b,Iterator)) # iner change a list to a iterator
print("----b.next----\n")
print(str(b.__next__()).strip())
print(b.__next__())
print(b.__next__())

 

posted on 2022-01-01 22:56  ttm6489  阅读(23)  评论(0编辑  收藏  举报

导航