gpt4 book ai didi

Python 相当于 Ruby 的 each_with_index?

转载 作者:太空狗 更新时间:2023-10-29 17:48:08 25 4
gpt4 key购买 nike

<分区>

在 Ruby 中,如果我有一个数组并且我想在循环中同时使用索引和值,我会使用 each_with_index

a=['a','b','c']
a.each_with_index{|v,i| puts("#{i} : #{v}") }

打印

0 : a 
1 : b
2 : c

做同样事情的 Pythonic 方式是什么?

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