美文网首页
python中iter()函数

python中iter()函数

作者: 帅子锅 | 来源:发表于2017-08-12 17:56 被阅读0次

iter()函数就是生成一个迭代器,迭代器必须用__next__方法才会调用一次,如下

>>> myTuple = (123,‘xyz’,45.67)
>>> i = iter(myTuple)
>>> i.next()
123
>>> i.next()
‘xyz’
>>> i.next()
45.67
>>> i.next()
Traceback (most recent call last):
File “<stdin>”,line 1,in <module>
StopIteration

>>>lst = [1, 2, 3]
>>> for i in iter(lst):
...     print(i)
... 
1
2
3

相关文章

  • python中iter()函数

    iter()函数就是生成一个迭代器,迭代器必须用__next__方法才会调用一次,如下

  • python iter函数用法

    iter函数用法简述 Python 3中关于iter(object[, sentinel)]方法有两个参数。 使用...

  • 可迭代对象、迭代器、生成器

    接触Python迭代器之前,先来了解序列可以迭代的原因:iter函数内置的iter函数有以下作用。 检查对象是否实...

  • iteration

    今天,学习python的时候,忽然想起来 workshee.iter_rows() 方法单中,iter的词源是什么...

  • Python 迭代 Iteration

    for x in iter(iterable)迭代器 (Iterator): Python 中 for 循环实际操...

  • python3内置函数

    运行环境:python3.5.4 1.map() " map(func,iter)函数,用来将某个可迭代对象ite...

  • itertools常用方法

    interator tips: 从Python3.4开始,检查对象x是否迭代,最准确的方法是调用iter(x)函数...

  • Python排序

    一、sort,sorted函数介绍: Sort函数是list列表中的函数,而sorted可以对list或者iter...

  • python之__iter__函数与__next__函数

    https://blog.csdn.net/liweibin1994/article/details/77374854

  • Python 迭代器和生成器

    1. 迭代器 任何包含__iter__和__next__的函数将成为迭代器,而只包含__iter__的函数则是可迭...

网友评论

      本文标题:python中iter()函数

      本文链接:https://www.haomeiwen.com/subject/abyjrxtx.html