Locked lesson.
About this lesson
Exercise files
Download this lesson’s related exercise files.
Lists.docx58.9 KB Lists - Solution.docx
58.9 KB
Quick reference
Lists
Lists are exactly what they sound like...lists of items.
When to use
Use a list whenever you have items that you can store numerically.
Instructions
A list is...well...a list! To create one:
my_list = ["John", "Tim", "Mary"]
Lists can contain strings, numbers, variables, other lists, and just about anything else you can think of.
Items in a list are accessed by their numeric index number.
List item index numbers start with zero, and increase by one for each item in the list.
To print out an item in a list:
print(my_list[0])
To delete the first item in a list (or any item):
del my_list[0]
To add an item to the end of a list:
my_list.append("item to add")
Hints & tips
- my_list = ["John", "Tim", "Mary"]
- print(my_list[0])
- List item index numbers start at zero
Lesson notes are only available for subscribers.