Challenge - 5 Problems
String Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of String Slicing and Concatenation
What is the output of the following Python code?
DSA Python
s = "hello" result = s[1:4] + s[0] print(result)
Attempts:
2 left
💡 Hint
Remember string slicing s[start:end] includes start but excludes end.
✗ Incorrect
The slice s[1:4] takes characters from index 1 to 3, which are 'e', 'l', 'l'. Adding s[0] which is 'h' results in 'ellh'.
🧠 Conceptual
intermediate2:00remaining
Understanding String Immutability
Which statement best describes why strings in Python are immutable?
Attempts:
2 left
💡 Hint
Think about what happens when you try to change a character in a string.
✗ Incorrect
Strings are immutable because any change creates a new string object; the original string's memory cannot be altered.
❓ Predict Output
advanced2:00remaining
Output of String Interning Behavior
What is the output of this code snippet?
DSA Python
a = "python" b = "python" c = ''.join(['p', 'y', 't', 'h', 'o', 'n']) print(a is b) print(a is c)
Attempts:
2 left
💡 Hint
The 'is' operator checks if two variables point to the same object in memory.
✗ Incorrect
String literals like 'python' are interned and share the same memory, so a is b is True. But c is created dynamically, so a is c is False.
🔧 Debug
advanced2:00remaining
Identify the Error in String Modification Attempt
What error does the following code raise?
DSA Python
s = "immutable" s[0] = 'I'
Attempts:
2 left
💡 Hint
Strings cannot be changed by assigning to an index.
✗ Incorrect
Strings are immutable in Python, so trying to assign a character to an index raises a TypeError.
🚀 Application
expert2:00remaining
Memory Size Comparison of Strings
Given two strings s1 = 'abc' and s2 = 'a' + 'b' + 'c', which statement about their memory usage is correct?
Attempts:
2 left
💡 Hint
Consider how Python handles string literals vs runtime concatenation.
✗ Incorrect
String literals like s1 may be interned, but s2 is created at runtime by concatenation, so they are different objects in memory.