14.4 Printing Lists and List Items

You can print lists just like you can print strings, integers, and floats. For example:

We can also print individual items by including the item index. The first item in the list has an index of 0, the second item in the list has an index of 1, the third item in the list has an index of 2, and so on. The index is listed beside the list name in square brackets. For example:

We can also print from the end of the list using a minus sign. The last item has an index of -1, the second last item has an index of -2, and so on. For example:

You can see from the above examples that "flour" can be printed using both ingredients[-8] and ingredients[0].

We can also print items in a list as part of a string

I can also print each item in a loop (you don't even need to include the index):

For the above example, the for-loop continues until all of the items in the list has been printed.

We can also format the items in the list to change capitalization using the built-in title command: