Check your understanding of the previous reading: string literals, quoting rules, escape characters, and how strings differ from numbers.
Select any of the following that are string literal values.
Select every one that is a string literal, then check.
A string literal needs a matching pair of quotes around it, single or double, both the same type. The quotes are what make it a string, not what is written inside them.
True or False: Strings are composed of only letters and symbols.
Select one answer, then check.
"5" can appear inside a string too.Think about a string like "5" or "Room 101": do the digits inside count as part of the string?
Consider the following statement:
"1" + "1" = "2"
True or False: is this statement correct?
Select one answer, then check.
+ operator concatenates strings instead of adding them numerically, so "1" + "1" evaluates to "11", not "2".+ operator on two strings joins their text rather than doing arithmetic, so the result is "11", not "2".Check what the + operator does when both sides are strings: does it add numbers, or does it join text?
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:
Two things matter for each blank: which quote character to use, and whether a backslash escape sequence is needed.
\t and \n.One correct way to write each literal:
a: "a" tab: "\t" new line: "\n" double quote: '"' single quote: "'" empty string: ""
Several blanks also have an equally correct alternate spelling that the word bank does not offer, since it only grades one spelling per blank. Either form is correct Python:
a: also 'a' (single quotes)"\"" (escaped, inside double quotes)'\'' (escaped, inside single quotes)'' (single quotes)Distractors (not used): A (wrong case), \t and \n (missing the quotes), " " (a space, not an empty string).