Python: Loop Thru List (Enumerate)

By Xah Lee. Date: . Last updated: .

Loop thru a list with item's values

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

for xx in aa:
    print(xx)

# a
# b
# c

Loop thru a list with item's index and value

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

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

# 0 a
# 1 b
# 2 c

Python Data Structure

Python

Overview

Help

Comment

String

Arithmetic

Boolean

Conditional

Loop

Data Structure

Function and Class

Module

Misc

Regex

Text Processing

Web

Misc