相关疑难解决方法(0)

构建一个基本的Python迭代器

如何在python中创建迭代函数(或迭代器对象)?

python iterator object

545
推荐指数
8
解决办法
34万
查看次数

如何检查对象是否是Python中的迭代器?

我可以检查一下next()方法,但这还够吗?有一种意识形态的方式吗?

python iterator

38
推荐指数
5
解决办法
1万
查看次数

在循环python中跳过多次迭代

我有一个循环列表,我想look在达到之后跳过3个元素.在这个答案中提出了一些建议,但我没有充分利用它们:

song = ['always', 'look', 'on', 'the', 'bright', 'side', 'of', 'life']
for sing in song:
    if sing == 'look':
        print sing
        continue
        continue
        continue
        continue
        print 'a' + sing
    print sing
Run Code Online (Sandbox Code Playgroud)

continue当然四次是胡说八道,使用四次next()是行不通的.

输出应如下所示:

always
look
aside
of
life
Run Code Online (Sandbox Code Playgroud)

python iterator loops continue next

37
推荐指数
2
解决办法
2万
查看次数

标签 统计

iterator ×3

python ×3

continue ×1

loops ×1

next ×1

object ×1