作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下程序
enum1 = enumerate("This is the test string".split())
我需要遍历 enum1 并使用 next() 函数打印所有索引项对。
我尝试通过执行以下操作来获取索引项对
for i in range(len(enum1)):
print enum1.next()
它抛出一个错误,显示 len()
不能应用于枚举。
谁能建议我使用 next()
函数遍历此枚举以打印所有索引项对的方法?
注意:我的要求是使用next()
函数来检索索引项对
最佳答案
只需使用:
for i,item in enum1:
# i is the index
# item is your item in enum1
或
for i,item in enumerate("This is the test string".split()):
# i is the index
# item is your item in enum1
这将使用下面的 next
方法...
关于python - 如何遍历枚举对象并使用 next() 函数打印所有索引项对?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6411127/
我是一名优秀的程序员,十分优秀!