开发者

Python loop with int iterator [duplicate]

开发者 https://www.devze.com 2023-04-03 14:33 出处:网络
This question already has answers here: Accessing the index in 'for' loops (26 answers) Closed 7 months ago.
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

精彩评论

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