Year 9 › Python II: lists and strings › Lesson 1 of 5
Year 9 · Autumn 1 · Python II: lists and strings Lists: creating and indexing
Topic 14 Programming further
KS3 Computing · Real programs keep data in lists, take text apart as strings, split work into subroutines, check their input, save to files, and get tested on purpose.
Programming Cambridge Lower Secondary Computing 0860
You will learn to Create a Python list with square brackets and print one item using its index. Explain why the first item is at index 0 and the last is at len(list) - 1. Use a negative index, like -1, to get the last item. Explain the error that an index past the end of the list gives.
Success criteria I can print the first and the last item of my shopping list. I can say which index holds the 4th item in a list. I can explain 'list index out of range' in my own words.
list One name holding many values in order. Also called an array.
index An item's position in a list, counting from 0.
Subroutine A named block of code you can call when needed.
Function A subroutine that returns a value.
Parameter A placeholder in a subroutine for a value passed in.
Validation Checking input is reasonable before using it.
Boundary data Test data at the very edge of what's allowed.
Lists A list (or array ) stores many values under one name, in order.
scores = [12, 45, 33, 50] ? Why?Why start at 0? The index means 'how many steps from the start'. The first item is 0 steps away.
scores[0] → 12scores[-1] → 50 (the last one)scores.append(28) adds to the endlen(scores) → how many itemsscores[10] → error: no item there
Mark this lesson as done Saved on this device.
← Back to Python II: lists and strings Next lesson → append, remove, len and in