Borys Borys - 1 year ago 264
Python Question

Python foreach equivalent

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]

or something like this.

Answer Source

Sure. A for loop.

for f in pets:
    print f
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download