Challenge - 5 Problems
String Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateString Immutability in Python
What is the output of this Python code snippet?
DSA Python
s = "hello" s[0] = 'H' print(s)
Attempts:
2 left
💡 Hint
Strings in Python cannot be changed after creation.
✗ Incorrect
Strings in Python are immutable. Trying to assign a new character to an index causes a TypeError.
❓ Predict Output
intermediateString Concatenation Performance
What is the output of this Python code?
DSA Python
result = '' for i in range(3): result += str(i) print(result)
Attempts:
2 left
💡 Hint
The loop appends string versions of numbers to result.
✗ Incorrect
The loop concatenates '0', '1', and '2' to the empty string, resulting in '012'.
❓ Predict Output
advancedString Interning Behavior
What is the output of this Python code snippet?
DSA Python
a = 'hello' b = 'hello' print(a is b)
Attempts:
2 left
💡 Hint
Python may reuse the same string object for identical literals.
✗ Incorrect
Python interns short strings, so 'a' and 'b' point to the same object, making 'a is b' True.
❓ Predict Output
advancedUnicode String Length
What is the output of this Python code?
DSA Python
s = 'naïve' print(len(s))
Attempts:
2 left
💡 Hint
Python 3 strings are Unicode and count characters, not bytes.
✗ Incorrect
The string 'naïve' has 5 characters including the 'ï' which counts as one character.
❓ Predict Output
expertMutable vs Immutable String-like Types
What is the output of this Python code?
DSA Python
from array import array s = 'abc' a = array('u', s) a[0] = 'z' print(''.join(a))
Attempts:
2 left
💡 Hint
array of type 'u' supports mutable Unicode characters.
✗ Incorrect
The array of Unicode characters is mutable, so changing index 0 to 'z' works and prints 'zbc'.
