Questions: String Basics

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

In Python, a student runs: s = 'Hello'; s[0] = 'h'. What happens?

As becomes 'hello' — the first character is lowercased in place
Bs becomes 'hHello' — the character is inserted at position 0
CA TypeError or similar error is raised — strings are immutable
DNothing happens — the assignment is silently ignored
Question 2 Multiple Choice

The string s = 'Python' has length 6. What is the value of s[5]?

A'o' — the fifth letter of Python
BAn IndexError — index 5 is out of range for a 6-character string
C'n' — the last character, at index 5
D'P' — index 5 counts 5 characters from the end
Question 3 True / False

In Python, every string operation that appears to modify a string actually creates a new string; the original string object is unchanged.

TTrue
FFalse
Question 4 True / False

In Python, the string '42' and the integer 42 can be used interchangeably in arithmetic expressions.

TTrue
FFalse
Question 5 Short Answer

Explain why string immutability is a useful design choice, not just a limitation. What problems would arise if strings could be modified in place?

Think about your answer, then reveal below.