0
0
Pythonprogramming~20 mins

Common string transformations in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
String Transformation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2:00remaining
Output of string strip and replace
What is the output of this Python code?
Python
text = "  Hello, World!  "
result = text.strip().replace(",", "")
print(result)
A" Hello World! "
B"Hello World!"
C"Hello, World!"
D"Hello,World!"
Attempts:
2 left
๐Ÿ’ก Hint
strip() removes spaces at start and end; replace() removes commas.
โ“ Predict Output
intermediate
2:00remaining
Result of string split and join
What is the output of this code?
Python
sentence = "Python is fun"
words = sentence.split()
result = "-".join(words)
print(result)
A"Python-is-fun"
B"Python is fun"
C"Python-isfun"
D"Python-is-fun-"
Attempts:
2 left
๐Ÿ’ก Hint
split() breaks string into words; join() connects them with dashes.
โ“ Predict Output
advanced
2:00remaining
Output of string formatting with f-string
What does this code print?
Python
name = "Alice"
age = 30
print(f"Name: {name.upper()}, Age: {age + 5}")
A"Name: ALICE, Age: 30"
B"Name: alice, Age: 35"
C"Name: Alice, Age: 30"
D"Name: ALICE, Age: 35"
Attempts:
2 left
๐Ÿ’ก Hint
upper() makes name uppercase; age + 5 adds 5 to age.
โ“ Predict Output
advanced
2:00remaining
Result of chained string methods
What is printed by this code?
Python
text = "  python Programming  "
result = text.strip().capitalize().replace("programming", "Coding")
print(result)
A"Python Programming"
B"Python coding"
C"Python Coding"
D"python Coding"
Attempts:
2 left
๐Ÿ’ก Hint
strip() removes spaces, capitalize() makes first letter uppercase, replace() swaps words.
โ“ Predict Output
expert
3:00remaining
Output of complex string slicing and methods
What is the output of this code?
Python
s = "DataScience"
result = s[1:9:2].lower() + s[-3:].upper()
print(result)
A"aaceNCE"
B"atcienceCE"
C"atcEENCE"
D"AaceNCE"
Attempts:
2 left
๐Ÿ’ก Hint
Slice with step 2 from index 1 to 9: indices 1('a'),3('a'),5('c'),7('e') -> 'aace'.lower(), then add last 3 uppercase.