Lists

1
Strings
PREVIEW12m 50s
2
Data Types
PREVIEW10m 7s

## Lists

You have seen how data can be stored in individual variables. However, what happens when you have a large number of related data?

Consider a school. The teacher needs to store the exam results for all of the pupils in a class. It might look like this:

mathsSusan = 67

mathsJohn = 83

mathsSam = 35

englishSusan = 92

englishJohn = 60

englishSam = 80

This starts to get unwieldy even with a class of three pupils studying only two subjects. If the teacher wanted to print these values, it would get very tedious:

print(mathsSusan)

print(mathsJohn)

and so on.

Fortunately, Python enables us to group related data using lists:

classMembers = ["Susan", "John", "Sam"]

mathsScore = [67, 83, 35]

englishScore = [92, 60, 80]

print(classMembers[0], mathsScore[0], englishScore[0])

print(classMembers[1], mathsScore[1], englishScore[1])

print(classMembers[2], mathsScore[2], englishScore[2])

This gives the following output:

Susan 67 92

John 83 60

Sam 35 80

Note that Python uses zero indexing.

These topics, and other collection types, are further explored in the next video.

When you’re ready, select the vertical Learning Path button to continue.

Difficulty
Beginner
Duration
26m
Students
158
Ratings
5/5
Description

Python for beginners - Data types, Strings and lists