Chapters
Python114 chapters

Exercises

Change Items

3 tasks. Write the code, press Check, and the page runs it against a real Python interpreter.

Exercise 1

Replace Grace with Alan, keeping the same list object.

Python
names = ["Ada", "Grace", "Katherine"]
# replace the middle name
print(names)
Exercise 2

Replace the two middle numbers with three letters, using a slice assignment.

Python
numbers = [1, 2, 3, 4, 5]
# replace positions 1 and 2 with 'a', 'b', 'c'
print(numbers)
Exercise 3

Change a so that b sees the new contents too.

Python
a = [1, 2, 3]
b = a
# make both show [7, 8]
print(a)
print(b)