0
0
Pythonprogramming~20 mins

String values and text handling in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
String Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this string slicing code?
Consider the following Python code that slices a string. What will be printed?
Python
text = "Programming"
print(text[3:8])
A"gramm"
B"gram"
C"grammi"
D"ogram"
Attempts:
2 left
💡 Hint
Remember that string slicing includes the start index but excludes the end index.
Predict Output
intermediate
2:00remaining
What does this code print with string methods?
What is the output of this Python code that uses string methods?
Python
s = "  Hello World  "
print(s.strip().lower().replace(' ', '_'))
A"hello world"
B" hello_world "
C"hello_world"
D"Hello_World"
Attempts:
2 left
💡 Hint
strip() removes spaces at both ends, lower() makes all letters lowercase, replace() changes spaces inside the string.
Predict Output
advanced
2:00remaining
What is the output of this multiline string and escape sequence code?
What will this Python code print?
Python
text = '''Line1\nLine2\tTabbed'''
print(text)
ALine1\nLine2\tTabbed
B
Line1
Line2	Tabbed
C
Line1
Line2\tTabbed
DLine1\nLine2 Tabbed
Attempts:
2 left
💡 Hint
Triple quotes preserve backslashes as literal characters unless raw strings are used.
Predict Output
advanced
2:00remaining
What is the output of this f-string with expressions?
What will this Python code print?
Python
name = "Alice"
age = 30
print(f"Name: {name.upper()}, Age next year: {age + 1}")
AName: ALICE, Age next year: 31
BName: alice, Age next year: 31
CName: ALICE, Age next year: 30
DName: Alice, Age next year: 31
Attempts:
2 left
💡 Hint
f-strings evaluate expressions inside curly braces before printing.
Predict Output
expert
3:00remaining
What is the output of this complex string manipulation code?
What will this Python code print?
Python
s = "abracadabra"
result = ''.join([c.upper() if i % 2 == 0 else c for i, c in enumerate(s)])
print(result)
AaBrAcAdAbRa
Babracadabra
CABRACADABRA
DAbRaCaDaBrA
Attempts:
2 left
💡 Hint
The code changes characters at even positions to uppercase and leaves odd positions unchanged.