05 - Introduction To Python - Arrays and Lists
05 - Introduction To Python - Arrays and Lists
Programming
I need to improve my
understanding of this skill.
What is an Array? What is a List?
• As opposed to a variable which can only hold one item of data, an
array can hold lots of data in a series of memory locations, each of
which can hold a single item of data.
• All data in an array must be of the same data type, for example an
array could hold a range of integers OR a range of string statements.
• However, in Python we use lists which can hold a range of different
data types, for example, a list could contain a mixture of string and
integer data.
Writing Python Arrays/Lists
• In python, lists are used instead of arrays.
• To begin, a list is declared in the same way as a variable. The difference is after the
equals symbol = you add square brackets [ ] and can add values within them, e.g.
START
numbers = [1,2,3,4,5,6,7,8,9,10]
OUTPUT: numbers
END
Task 1: Solution
• Add a print screen to show • Add a print screen to show
your coding here. your output solution here.
Task 2: Rookie
1. Create a list to store 5 names of your choice.
2. Output the list.
START
names = [Gareth, Lionel, Zlatan,
Rachel, Mia]
OUTPUT: names
END
Task 2: Solution
• Add a print screen to show • Add a print screen to show
your coding here. your output solution here.
Understanding Array/List structures
• A list is structured as follows:
Index 0 1 2 3 4 5 6 7 8 9 10 11
List Data 2 4 6 8 10 12 14 16 18 20 22 24
• Each box in the list can contain a data item. The individual boxes in the array
can be used just like variables.
• Each box has a numerical reference called an index that is used to refer to
the individual data item.
• Note that in Python the first element of the list shown here has an index
of zero.
• So in the above example, index 0 stores the number 2, index 6 stores the
number 14, etc.
Task 3: Understanding index
1. Output a specific value of a list by using this command:
2. Read the following lists. Using your understanding of list indexing, identify the correct data to
be output if the following commands were written;
Nintendo
Lucy
4
How to edit a list
Lists hold variable information, therefore the data stored can be changed. See the
table below which shows some of the common ways of editing your array:
2. Perform the editing techniques shown on the previous slide on the list and print screen the output.
1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
1 Mark
Programming Challenge: Rookie - Answer
• Add a print screen to show • Add a print screen to show
your coding here. your output solution here.
Add a print screen of
your solutions to the
Programming Challenge: Pro next slide.
1 Mark
Programming Challenge: Pro - Answer
• Add a print screen to show • Add a print screen to show
your coding here. your output solution here.
Add a print screen of
your solutions to the
Programming Challenge: Beast next slide.
1. Ask a user to input 5 numbers and store each of them in a list. Ask
the user to remove one of the inputted values.
2. Output the following information within suitable sentences;
• All the data stored in the list
• The length of the list
• The total value of the list
1 Mark
Programming Challenge: Beast - Answer
• Add a print screen to show • Add a print screen to show
your coding here. your output solution here.
Debugging Question
The following information needs to be put into a list:
1 Mark
Complete the table below to help you identify what
Challenges Review areas you are confident at and which areas you need
to improve further:
Challenge Your Score (Max 1 mark each)
Rookie Challenge
Pro Challenge
Beast Challenge
Debugging Challenge
Unit Review
What Went Well: