Python lists are zero-indexed i.e. the first element is at index 0, the second element is at index 1 and so on. To access a specific element of a list, we can do so by writing the list’s name followed by square brackets with the index of the element we want to access.
myList = ["a", "b", "c", "d", "e"]
# Printing second element of list
print(myList[1])
# "b"
# Printing fourth element of list
print(myList[3])
# "d"
In the exercise, python_topics is a list whose elements are strings.
A while loop is being used in the exercise to iterate over the index i.e. in the first iteration, index will be 0, in the second iteration, index will be 1 and so on.
But we don’t want to print the index. Instead we want to print the element at that particular index. python_topics[index] will allow us to access the string element at that particular index.
print('I am learning about ' + python_topics[index])
In each iteration of the while loop, the + operator will concatenate/join the string 'I am learning about ' with one of the string elements so that we get outputs such as:
"I am learning about variables"
"I am learning about control flow"
...