Access Index of a List in Python Using for Loop

(Last Updated On: 18/01/2023)

Python Program to Access Index of a List Using for Loop

# Python Program to Access Index of a List Using for Loop
sample_list = ["Welcome", "to", "the", "fascinating", "world", "of", "Python"]

for index, val in enumerate(sample_list):
    print("index:", index, "| value:", val)

Output:

index: 0 | value: Welcome
index: 1 | value: to
index: 2 | value: the
index: 3 | value: fascinating
index: 4 | value: world
index: 5 | value: of
index: 6 | value: Python

Leave a Reply

Your email address will not be published. Required fields are marked *