Hands-On Python

Lesson 10. Data Structures Part I: List

Most programming languages have the concept of an array. Arrays are sequences of values usually all of the same data type.
Python took the concept of an array and made it much more powerful by creating three different data structures. Each structure has it’s uses which we will explore in later lessons.
In the next three lessons, we are going to talk about how to create these unique data structures and how to work with them. The first structure we are going to talk about is called a list.
A list is the closest structure to a classic array. Arrays have methods that allow you to work with the data stored in them.


Example #1 Creating List
Unlike simpler data types, list can be created without initial values.
empty_list = []
fighters = ['Eagle', 'Falcon', 'Tomcat']
Example #2 Adding Values To An Existing List
fighters.append('Lightning II')
Example #3 Accessing Values In A List
List values are accessed using an index number that represents the position of a value in the list. The index starts at 0 and the last value can be accessed using an index value of -1.

Now you try it!

Don't copy and past. Type the code yourself!