Python String Manipulation Fundamentals Quiz
A 35-question quiz covering Python string manipulation concepts, including slicing, searching, formatting, immutability, transformations, and real-world text-processing patterns.
Question 1
What does it mean when we say that Python strings are immutable?
Question 2
Which operator is commonly used to check if a smaller string exists within a larger one?
Question 3
A developer wants to remove leading and trailing spaces from user input. Which string method is typically used?
Question 4
Why is slicing commonly used when working with substrings?
Question 5
Which method is used to replace all occurrences of a substring with another substring?
Question 6
A text-processing script needs to standardize case to avoid mismatches in comparisons. Why is lower() commonly used for this?
Question 7
Why might a developer use join() instead of repeated string concatenation inside a loop?
Question 8
Which method is often used to split a string into a list of words using whitespace as the default delimiter?
Question 9
What does the startswith() method return when a string begins with the provided prefix?
Question 10
A file-import application encounters product codes that include extra spaces or formatting errors. To prepare these codes for system matching, the program removes whitespace and makes them lowercase. Why is combining strip() and lower() an effective solution?
Question 11
A developer needs to extract the first three characters from a tracking code but must avoid errors even when the code is shorter than expected. Why is slicing such as code[:3] a safe approach?
Question 12
A data cleanup pipeline receives email addresses, some of which contain uppercase letters. To ensure consistent matching when searching through user records, the script converts each email to lowercase. Why is this a common pattern?
Question 13
What is printed by the following code?
text = "Hello"
print(text[1])Question 14
What does this code output when slicing the last three characters?
code = "A1B2C3"
print(code[-3:])Question 15
What is the result of calling upper()?
msg = "hello!"
print(msg.upper())Question 16
What prints from this substring replacement?
x = "bananas"
print(x.replace("na", "NA"))Question 17
What does this split operation produce?
line = "a,b,c"
print(line.split(","))Question 18
What is printed by this join() operation?
items = ["x", "y", "z"]
print("-".join(items))Question 19
What is printed after using strip()?
val = " hello "
print(val.strip())Question 20
What does this code print?
txt = "ABCDE"
print(txt[::2])Question 21
What does endswith() return here?
file = "report.pdf"
print(file.endswith(".pdf"))Question 22
What is the result of counting substring occurrences?
print("mississippi".count("ss"))Question 23
What does this format operation output?
name = "Ana"
print(f"Hello, {name}!")Question 24
What happens in this reverse-string slice?
print("python"[::-1])Question 25
What does this code output?
message = "Hello"
print(len(message))Question 26
What does splitlines() do here?
text = "a\nb\nc"
print(text.splitlines())Question 27
What is the result of calling capitalize()?
print("python".capitalize())Question 28
What is the output of this concatenation?
print("ab" + "cd")Question 29
What does zfill() do here?
print("42".zfill(5))Question 30
What happens in this formatting example?
print("Value: {}".format(10))Question 31
What does this membership test return?
print("cat" in "concatenate")Question 32
What is printed by this stripping example?
print("xxhelloxx".strip("x"))Question 33
What is printed by swapping case?
print("AbC".swapcase())Question 34
What does find() return here?
print("hello".find("l"))Question 35
What is the result of using replace() to remove characters?
print("a-b-c".replace("-", ""))