Starter quiz
- What is the correct syntax in Python to initialise a variable called age and set its value to the numerical value 13?
- `age (13)`
- `age = 13` ✓
- `age = "13"`
- `set age to 13`
-
- What is the correct syntax in Python to initialise a variable called name and set its value to Laura?
- `name (Laura)`
- `name ("Laura")`
- `name = "Laura"` ✓
- `name = Laura`
-
- Which programming construct is used to repeatedly perform actions in a program?
- sequence
- selection
- iteration ✓
- decomposition
-
- ______ are used to tell a program whether a condition has been met or not.
- 'Flags' ✓
- A while loop will run ...
- a set number of times.
- until a condition is no longer met. ✓
-
- ```colours = ["red", "blue", "yellow", "green"] print (colours[1])``` What colour would be printed by the program?
- red
- blue ✓
- yellow
- green
-
Exit quiz
- A ______ is a data type that is a collection of characters.
- 'string' ✓
- Lists are ______, which means that their contents can be modified, without having to create a new list.
- 'mutable' ✓
- Which code would check the first character of name1 does not appear anywhere in name2?
- `name1[0] == name2[0]`
- `len(name1) != len(name2)`
- `name1[0] not in name2` ✓
-
- Which of the following statements about strings is true?
- Strings are mutable.
- Strings are immutable. ✓
- Strings can only hold letters.
-
- What code would you use if you wanted to check the value of the first letter held in the string: `message = "Hello"`?
- `message[0]` ✓
- `message[1]`
- `message["H"]`
- `message[first]`
-
- If you update the value held by a string, the previous value is ______.
- 'overwritten' ✓
Worksheet
Loading worksheet ...
Presentation
Loading presentation ...
Video
Lesson Details
Key learning points
- Condition-controlled iteration is implemented using while loops in Python.
- A string is like a list in structure but is immutable, so elements cannot be changed, added or removed.
- Some operations that can be performed on lists can also be performed on strings.
Common misconception
Strings are mutable meaning that any character within the string can be changed.
Strings are immutable. The elements of a string cannot be changed. If changes to the string are required, the whole string must be rewritten.
Keywords
Iteration - the process of repeating a sequence of instructions within a program loop
String - a data type that is a collection of characters
Mutable - able to be changed
Immutable - not able to be changed
+