gpt4 book ai didi

Python foreach 等价物

转载 作者:IT老高 更新时间:2023-10-28 12:31:08 28 4
gpt4 key购买 nike

我正在深入研究 Python,但我有一个关于 foreach 迭代的问题。我是 Python 新手,在 C# 方面有一些经验。所以我想知道,Python中是否有一些等效的函数可以对我的集合中的所有项目进行迭代,例如

pets = ['cat', 'dog', 'fish']
marks = [ 5, 4, 3, 2, 1]

或类似的东西。

最佳答案

当然。一个 for 循环。

for f in pets:
print f

关于Python foreach 等价物,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40346498/

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