Check your understanding of the previous reading: string literals, quoting rules, escape characters, and how strings differ from numbers.

Question 1

Select any of the following that are string literal values.

Select every one that is a string literal, then check.

  • Correct. This is valid, complete, quoted text, so it is a string literal no matter what is written inside the quotes.
  • Not quite. There are no quotes here, so Python reads this as a bare identifier, a variable name, not a literal value.
  • Correct. It is fully quoted with matching double quotes, so it is a string literal even though the text inside looks like a variable name.
  • Not quite. Without quotes, this is a bare identifier, not a string literal.
  • Not quite. Without quotes, this is an integer literal, not a string.
  • Not quite. The opening quote is never closed with a matching quote, so this is not a valid literal at all.
  • Not quite. The opening single quote is closed with a double quote instead of a matching single quote, so this is not a valid literal.

Question 2

True or False: Strings are composed of only letters and symbols.

Select one answer, then check.

  • Correct. Strings are made of letters, numbers, and symbols, so digits like the 5 in "5" can appear inside a string too.
  • Not quite. Strings can also contain digits, so limiting them to only letters and symbols leaves out numbers.

Question 3

Consider the following statement:

"1" + "1" = "2"

True or False: is this statement correct?

Select one answer, then check.

  • Correct. The + operator concatenates strings instead of adding them numerically, so "1" + "1" evaluates to "11", not "2".
  • Not quite. Python's + operator on two strings joins their text rather than doing arithmetic, so the result is "11", not "2".

Question 4

How do you write each of the following as a Python string literal?

The first letter of the alphabet, lower case:

A tab character:

A new line:

A double quote:

A single quote:

The empty string:

Word bank — not all words are used