gpt4 book ai didi

python - 选择列表中下一个元组的命令

转载 作者:太空狗 更新时间:2023-10-30 03:03:26 26 4
gpt4 key购买 nike

我想知道是否有任何命令可以自动选择元组中的下一个项目而无需我输入它?

例如。

nul = 0

noofvalue = 5

value = ['a', 'b', 'c', 'd', 'e']

for nul < noofvalue:

file.write(value[0])

我可以在这里使用什么命令将“值”加 1,这样当文件循环时,它不使用值 [0],而是使用值 [1]?

nul = nul + 1

我用谷歌搜索了答案并进行了搜索,但我不明白他们在说什么,因为我对计算机编码非常陌生,所以请原谅我的无知。

最佳答案

我想你想要的是enumerate() .我将添加我自己的示例,因为您的示例有点奇怪:

>>> L = ['a', 'b', 'c', 'd', 'e']
>>> for index, value in enumerate(L):
... try:
... print L[index+1] # Prints the next item in the list
... except IndexError:
... print 'End of the list!'
...
b
c
d
e
End of the list!

关于python - 选择列表中下一个元组的命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18996185/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com