Check your understanding of the previous reading: strings and lists as sequences, and what split returns.

Question 1

True or false: Strings are sequences of characters, and lists are sequences of any type.

Select one answer, then check.

  • Correct. A string holds characters, while a list can hold elements of any type. Both are sequences, so you can iterate over either one with a for loop.
  • Not quite. Strings are sequences of characters, but lists can be a sequence of anything, so the statement is true.

Question 2

What is the type of the result of the following expression?

"1,2,3,4".split(",")

Select one answer, then check.

  • Correct. split returns a list of the pieces: ['1', '2', '3', '4'].
  • Not quite. Each piece is a string, but split returns the pieces together in a list.
  • Not quite. split doesn't count or convert anything; it returns a list of the pieces of the string.
  • Not quite. Splitting on a comma is valid; the reading splits desserts the same way.

Question 3

What is the element type of the result of the following expression?

"1,2,3,4".split(",")

Select one answer, then check.

  • Not quite. The result itself is a list, but this question asks about its elements.
  • Correct. Each element is a piece of the original string: '1', '2', '3' and '4' are strings, not numbers.
  • Not quite. The pieces look like numbers, but split keeps them as strings; converting them takes int, as in the Input/Split/Loop pattern.
  • Not quite. The expression is valid and returns ['1', '2', '3', '4'].