Loading...
A string is an ordered sequence of characters; a list stores an ordered collection. Python uses zero-based indexing, so a list of length n has normal non-negative indexes 0 through n−1. Traversal processes elements in a useful order. Distinguish an element from its index. A two-dimensional structure can represent rows and columns; apply the indexing convention consistently. Validate an index before using it when input may be invalid.
Video by Craig'n'Dave. The video’s own board label is retained; follow the specification reference and scope notes on this lesson for assessed content.
Viewing focus: Process strings and lists with indexes
After watching, attempt these questions before opening the answers. You can also use the written lesson below.
After watching 1: What is the first ordinary Python list index?
0. Zero-based indexing starts at zero.
After watching 2: What does a function parameter represent?
An input name used by the function. An argument supplies its value for a call.
What you'll be able to do
A string is an ordered sequence of characters; a list stores an ordered collection. Python uses zero-based indexing, so a list of length n has normal non-negative indexes 0 through n−1. Traversal processes elements in a useful order. Distinguish an element from its index. A two-dimensional structure can represent rows and columns; apply the indexing convention consistently. Validate an index before using it when input may be invalid.
A function packages a named task with parameters and, where appropriate, a return value. Parameters receive the supplied arguments for that call. Local variables are scoped to the function, reducing accidental interference. Returning a value is different from printing it: the caller can use a returned value in another calculation. Decomposition into subprograms improves readability and testing when each has a clear responsibility.
Opening a file in write mode can replace existing contents, while append mode adds to them. Reading retrieves stored text that may need parsing or conversion. Close files reliably; Python’s with statement helps manage that resource. Validate format and handle expected errors appropriately instead of assuming every line is valid. Keep file I/O separate from pure calculations when useful so data-processing logic can be tested without repeatedly changing real files.
def count_passes(scores):
return sum(1 for score in scores if score >= 50)
print(count_passes([49, 50, 80]))Scroll horizontally to see the full code or table.Attempt these problems on paper before opening the worked reasoning. Explain your steps as well as giving a final answer.
Common mistakes to avoid
Key takeaways
Question 1: Why is return often more reusable than printing inside a calculation function?
Return separates calculation from presentation.
Check the assessed scope and practical or mathematical requirements.
An external explanation or interactive activity to use alongside the lesson. It may include extension material.
Close the notes and answer from memory. Revisit any explanation you cannot yet reconstruct.
Test yourself
Answer a few questions, then review anything you missed.
Start with the quiz above to check the key ideas. You can also choose another topic from the practice library.