Good. The special
for loop is extremely useful, but what if we want to know the index of the current element inside the loop? For instance, we want to print the company name as well as its position in the list. To do so, we can construct our loop in the following way:
# print each company
for i in range(0, len(companies)):
print(companies[i] + ' is number ' + str(i+1) + ' in Europe.')
This time, we defined a temporary variable named
i (that's a frequent name, but again, you can call it anything) in the range from 0 (which is the first index) up to, but not including, the length of the list (which is the maximum valid index plus one).
In this way, we can use
companies[i] to access a given element, and we can still print
i to get the position in the ranking. Note that because indices start at 0 instead of 1, we used
str(i+1) to start numbering from 1.