开发者

Python loop with int iterator [duplicate]

This question already has answers here: Accessing the index in 'for' loops (26 answers) Closed 7 months ago.

I seem to开发者_JAVA百科 recall there is a built-in way of doing this:

i = 0
for value in values:
    # ...Stuff
    i += 1

but in a neater syntax; something like

for value, i in fn(values):
    # ...Stuff

Is my memory correct; and if so, what is the way of doing this?


for i, value in enumerate(values):
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜