0
0
Pythonprogramming~20 mins

String immutability in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
String Immutability Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2:00remaining
Output of string modification attempt
What is the output of this Python code?
Python
s = "hello"
s[0] = 'H'
print(s)
ATypeError
BHello
Chello
DSyntaxError
Attempts:
2 left
๐Ÿ’ก Hint
Remember that strings cannot be changed by assigning to an index.
โ“ Predict Output
intermediate
2:00remaining
Result of string concatenation
What is the output of this code?
Python
s = "cat"
s = s + "s"
print(s)
Acat
Bcats
CTypeError
Dcatss
Attempts:
2 left
๐Ÿ’ก Hint
Concatenation creates a new string.
โ“ Predict Output
advanced
2:00remaining
Output after string replace method
What is printed by this code?
Python
s = "banana"
s.replace('a', 'o')
print(s)
Abanana
Bbonono
CSyntaxError
DTypeError
Attempts:
2 left
๐Ÿ’ก Hint
Does the replace method change the original string?
โ“ Predict Output
advanced
2:00remaining
Value of string after slicing and concatenation
What is the output of this code?
Python
s = "python"
s = 'J' + s[1:]
print(s)
AnohtyJ
Bpython
CJython
DTypeError
Attempts:
2 left
๐Ÿ’ก Hint
Slicing creates a new string; concatenation creates a new string.
โ“ Predict Output
expert
2:00remaining
Final string value after chained operations
What is the output of this code?
Python
s = "immutable"
s1 = s.upper()
s2 = s1.replace('A', '@')
s3 = s2.lower()
print(s3)
Aelb@tummi
Bimmutable
CIMMUT@BLE
Dimmut@ble
Attempts:
2 left
๐Ÿ’ก Hint
Check the order of operations and what each method returns.