Sequences Preparation
Overview
Lists and strings are two kinds of sequences that have some similar functionality in Python. Today’s focus will be on using these two types of sequences.
Basic Learning Objectives
Before class, you should be able to:
- Create a list in Python
- Create a string in Python
- Identify the syntax for indexing into, slicing, and concatenating sequences
Advanced Learning Objectives
After class, you should be able to:
- Use the functionality of strings and lists to solve problems
Readings
You should complete the following readings/videos and embedded checks in Runestone:
- 8.1 Introduction: Sequences
- 8.2 Strings and Lists
- 8.3 Index Operator
- 8.5 Length
- 8.6 The Slice Operator
- 8.7 Concatenation and Repetition
- 9.9 Non-mutating Methods on Strings - reference for some more useful string methods
- Feel free to read the other sections if you’d like to know about more operations
Checks
Submit answers to the following on Moodle:
- What will the output be for the following code? (Checkpoint 8.10.1)
let = "z" let_two = "p" c = let_two + let m = c*5 print(m) - Write a program that extracts the last three items in the list
sportsand assigns it to the variablelast. Make sure to write your code so that it works no matter how many items are in the list. (Checkpoint 8.10.2)