相当于Python foreach [英] Python foreach equivalent
本文介绍了相当于Python foreach的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在研究Python,但我有一个关于foreach迭代的问题.我是Python的新手,并且在C#中有一些经验.所以我想知道,Python是否在我集合中的所有项目上都具有等效的迭代功能.
I am diving into Python and I have a question about foreach iteration. I am new to Python and I have some experience in C#. So I am wondering, if there is some equivalent function in Python for iteration all over all items in my collection, e.g.
pets = ['cat', 'dog', 'fish']
marks = [ 5, 4, 3, 2, 1]
或类似的东西.
推荐答案
好的.一个for循环.
Sure. A for loop.
for f in pets:
print f
这篇关于相当于Python foreach的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文