Back to questions
JuniorTheoryCommon
What happens when this program runs?
s = "hello"
print(s)
s[0] = "J"
print(s)Prints hello, then a TypeError
- Expecting
Jello, as if a string could be changed in place: strings are immutable, sos[0] = "J"raisesTypeErrorand the secondprintnever runs. - Expecting the error before
hello: only a syntax error stops a file before it starts, and this one comes at its own line, after the firstprint.
- How would you build the string
Jellofroms? - Which part of the error message names the type that cannot be changed?