循环中获取索引

如果像 C 或者 PHP 那样加入一个状态变量那就太不 pythonic 了

最好的选择就是用内建函数 enumerate()

for idx, val in enumerate(ints):
    print(idx, val)

Last updated