get index in foreach py

for idx, val in enumerate(ints):
    print(idx, val)

Here is what the above code is Doing:
1. We create a list of integers called ints.
2. We use a for loop to iterate over the integers in the list.
3. We print out the index of each integer and the integer itself.

As you can see, the index of each integer is printed before the integer itself.

Now let’s try something a bit more challenging.

Print out the index of each character in the string “Hello, world!”

Expected output:

0 H
1 e
2 l
3 l
4 o
5 ,
7 w
8 o
9 r
10 l
11 d
12 !