Exercise 34: Accessing Elements of Lists
Lists are pretty useful, but unless you can get at the things in them they aren't all that good. You can already go through the elements of a list in order, but what if you want say, the fifth element? You need to know how to access the elements of a list. Here's how you would access the first element of a list:
animals = ['bear', 'tiger', 'penguin', 'zebra'] bear = animals
You take a list of animals, and then you get the first (1st) one using 0?! How does that work? Because of the way math works, Python starts its lists at 0 rather than 1. It seems weird, but there are many advantages to this, even though it is mostly arbitrary.