Strings as lists

In many ways, strings act as a list of their composite characters. Let’s compare:

# TODO: run me
word = "hello"
word_as_list = ["h", "e", "l", "l", "o"]

Start interactive mode
# TODO: same length?
print(len(word))
print(len(word_as_list))

Start interactive mode
# TODO: same indexing?
print(word[0])
print(word_as_list[0])
print(word[2])
print(word_as_list[2])
print(word[4])
print(word_as_list[4])

Start interactive mode

That’s pretty much it for this section. When we learn about for loops, we’ll see how we can treat lists and strings as the same in that context as well.