Challenge - 5 Problems
String Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
β Predict Output
intermediate2:00remaining
String 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
intermediate2:00remaining
String 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
advanced2:00remaining
String 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
advanced2:00remaining
Unicode 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
expert2:00remaining
Mutable 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'.