An iterable is any object you can iterate through (loop through). For loops are a powerful tool when combined with iterables.
These include tuples, lists, dictionaries, and strings. We will dive deeper into these later, but for now, let's look at lists and strings.
You can make a list by listing elements separated by commas in square brackets, [].
For example:
color_list = [ "green", "blue", "red"]
number_list = [3, 7, 12, 15]
empty_list = []
We will learn much more about lists later, but I want you to be able to practice iterating through them.
Instead of iterating through a range object, you can iterate through any other iterable, including a list.
The iterator takes on the value of each element in the list.
For example, the following loop will print each color in color_list:
color_list = ["blue", "green", "red"]
for color in color_list:
print( color )
Python treats a string like an iterable list of characters.
For example, if you convert the string "word" to a list, you will see ["w", "o", "r", "d"]
The following loop prints each character in the string one at a time:
name_string = "Mr. McClung"
for character in name_string:
print( character )