Difficulty: beginner
Estimated Time: 15 minutes

This module will be focused on beginning sequences; namely lists, and iterating over them.

F5CA Python 002 Lesson 2 - Introduction to Sequences

Step 1 of 6

Basic Lists

List syntax

If needed, start up the python intepreter.


Lists are straightforward to create in Python:

my_list = [] # creation of empty list
another_list = [1,2,3]
yet_another = list()

Accessing list data is also simple; use [] notation, similar to Java / C++.

my_list = ['red', 'blue']

Lists support slicing and many of the same functions strings support such as the len() function

my_list = ['red', 'blue', 'yellow', 'orange']

You can also easily combine two lists:

list_one = ['red', 'green']
list_two = ['yellow', 'blue']
combine_list = list_one + list_two

Mixing types in a list (I don't recommend doing this):

python list_one = ['red', 1, True] print(list_one)