Python: Iterate List

By Xah Lee. Date: . Last updated: .

Go Thru Values

aa = ["a", "b", "c"]

for xx in aa:
    print(xx)

# a
# b
# c

Go Thru Index and Value

bb = ["a", "b", "c"]

for ii, vv in enumerate(bb):
    print(ii, vv)

# 0 a
# 1 b
# 2 c

enumerate() adds a counter to an iterable (such as a list, tuple, or string) and returns it as an enumerate object. This object yields pairs of index and value tuples.

Python, Loop

Python, Data Structure