Welcome to the Python String Manipulation MCQ Quiz! String manipulation is an important facet of programming, permitting builders to change, concatenate, search, and extract data from strings effectively. Python supplies a wealthy set of built-in capabilities and strategies for string manipulation, making it a strong language for dealing with textual content knowledge. This quiz goals to check your understanding of varied ideas associated to Python string manipulation, together with string strategies, formatting, slicing, concatenation, and common expressions. Every query is multiple-choice, with just one right reply. Take your time to fastidiously learn every query and select the best choice. Let’s discover the world of Python string manipulation collectively!

30+ MCQs on Python String Manipulation
Q1. What does the next Python code snippet do?
string = "Howdy, World!"
print(string.higher())
a) Prints “Howdy, World!” in lowercase
b) Converts “Howdy, World!” to uppercase and prints it
c) Reverses the string “Howdy, World!”
d) Removes all whitespace characters from the string “Howdy, World!”
Reply: b
Clarification: The higher()
technique converts all characters within the string to uppercase.
Q2. How will you concatenate two strings in Python?
a) Utilizing the concat()
technique
b) Utilizing the be a part of()
technique
c) Utilizing the &
operator
d) Utilizing the +
operator
Reply: d
Clarification: The +
operator is used for string concatenation in Python.
Q3. What’s the output of the next Python code snippet?
string = "Howdy, World!"
print(string[3:7])
a) “Howdy”
b) “lo, “
c) “lo, W”
d) “lo, World”
Reply: b
Clarification: Slicing is used to extract a substring from a string. The indices 3:7 characterize the substring ranging from index 3 (inclusive) as much as index 7 (unique).
This autumn. Which technique is used to separate a string into an inventory of substrings primarily based on a delimiter in Python?
a) break up()
b) substring()
c) separate()
d) divide()
Reply: a
Clarification: The break up()
technique is used to separate a string into an inventory of substrings primarily based on a delimiter.
Q5. What does the strip()
technique do in Python string manipulation?
a) Removes all whitespace characters from each ends of the string
b) Removes all characters besides alphabets from the string
c) Converts the string to uppercase
d) Converts the string to lowercase
Reply: a
Clarification: The strip()
technique removes main and trailing whitespace characters from the string.
Q6. How will you examine if a string incorporates a particular substring in Python?
a) Utilizing the incorporates()
technique
b) Utilizing the in
key phrase
c) Utilizing the search()
perform
d) Utilizing the hasSubstring()
technique
Reply: b
Clarification: The in
key phrase is used to examine if a substring exists inside a string in Python.
Q7. What does the substitute()
technique do in Python string manipulation?
a) Deletes all occurrences of a substring from the string
b) Replaces the primary incidence of a substring with one other substring
c) Replaces all occurrences of a substring with one other substring
d) Inserts a substring into the string at a specified place
Reply: c
Clarification: The substitute()
technique replaces all occurrences of a substring with one other substring within the string.
Q8. What’s the output of the next Python code snippet?
string = "Howdy, World!"
print(string.rjust(20))
a) ” Howdy, World!”
b) “Howdy, World! “
c) ” Howdy, World! “
d) “Howdy, World! “
Reply: a
Clarification: The rjust()
technique right-aligns the string in a subject of width 20 by padding it with areas on the left.
Q9. Which technique is used to search out the index of the primary incidence of a substring in a string in Python?
a) discover()
b) search()
c) index()
d) find()
Reply: a
Clarification: The discover()
technique returns the index of the primary incidence of a substring within the string, or -1 if the substring will not be discovered.
Q10. What does the isdigit()
technique do in Python string manipulation?
a) Checks if all characters within the string are digits
b) Converts the string to lowercase
c) Checks if all characters within the string are alphabets
d) Checks if the string is empty
Reply: a
Clarification: The isdigit()
technique returns True
if all characters within the string are digits, in any other case False
.
Q11. What’s the output of the next Python code snippet?
string = "Howdy, World!"
print(string.break up(","))
a) [“Hello”, “World!”]
b) [“Hello,”, “World!”]
c) [“Hello”]
d) [“World!”]
Reply: a
Clarification: The break up()
technique splits the string into an inventory of substrings primarily based on the desired delimiter (,
on this case).
Q12. How will you examine if a string begins with a particular substring in Python?
a) Utilizing the startswith()
technique
b) Utilizing the beginwith()
technique
c) Utilizing the begin()
technique
d) Utilizing the isstart()
technique
Reply: a
Clarification: The startswith()
technique is used to examine if a string begins with a particular substring in Python.
Q13. What does the be a part of()
technique do in Python string manipulation?
a) Joins the weather of an inventory right into a single string
b) Splits the string into an inventory of substrings
c) Reverses the string
d) Converts the string to uppercase
Reply: a
Clarification: The be a part of()
technique joins the weather of an inventory right into a single string utilizing the desired delimiter.
Q14. How will you take away main whitespace characters from a string in Python?
a) Utilizing the trim()
technique
b) Utilizing the remove_leading_whitespace()
technique
c) Utilizing the lstrip()
technique
d) Utilizing the strip()
technique
Reply: c
Clarification: The lstrip()
technique removes main whitespace characters from the string.
Q15. Which technique is used to transform the primary character of a string to uppercase in Python?
a) higher()
b) capitalize()
c) title()
d) first_upper()
Reply: b
Clarification: The capitalize()
technique converts the primary character of a string to uppercase.
Q16. How will you examine if a string ends with a particular substring in Python?
a) Utilizing the endwith()
technique
b) Utilizing the isend()
technique
c) Utilizing the endswith()
technique
d) Utilizing the isendwith()
technique
Reply: c
Clarification: The endswith()
technique is used to examine if a string ends with a particular substring in Python.
Q17. What’s the output of the next Python code snippet?
string = "Howdy, World!"
print(string.discover("o"))
a) 4
b) 6
c) 7
d) -1
Reply: a
Clarification: The discover()
technique returns the index of the primary incidence of a substring within the string, or -1 if the substring will not be discovered.
Q18. Which technique is used to transform all characters in a string to lowercase in Python?
a) decrease()
b) uppercase()
c) to_lower()
d) toLower()
Reply: a
Clarification: The decrease()
technique is used to transform all characters in a string to lowercase.
Q19. What does the isalpha()
technique do in Python string manipulation?
a) Checks if all characters within the string are alphabets
b) Checks if all characters within the string are digits
c) Checks if the string is empty
d) Checks if the string incorporates any non-alphanumeric characters
Reply: a
Clarification: The isalpha()
technique returns True
if all characters within the string are alphabets, in any other case False
.
Q20. What’s the output of the next Python code snippet?
string = "Howdy, World!"
print(string.substitute("World", "Python"))
a) “Howdy, Python!”
b) “Howdy, World!”
c) “Python, World!”
d) “Python, Python!”
Reply: a
Clarification: The substitute()
technique replaces all occurrences of a substring with one other substring within the string.
Q21. How will you examine if all characters in a string are digits in Python?
a) Utilizing the isdigit()
technique
b) Utilizing the isnumeric()
technique
c) Utilizing the isnumber()
technique
d) Utilizing the all_digits()
technique
Reply: a
Clarification: The isdigit()
technique returns True
if all characters within the string are digits, in any other case False
.
Q22. What does the title()
technique do in Python string manipulation?
a) Converts the string to uppercase
b) Converts the string to lowercase
c) Capitalizes the primary character of every phrase within the string
d) Reverses the string
Reply: c
Clarification: The title()
technique capitalizes the primary character of every phrase within the string.
Q23. What’s the output of the next Python code snippet?
string = " Howdy, World! "
print(string.strip())
a) “Howdy, World!”
b) “Howdy, World!”
c) ” Howdy, World! “
d) “Howdy, World! “
Reply: a
Clarification: The strip()
technique removes main and trailing whitespace characters from the string.
Q24. Which technique is used to examine if a string incorporates solely whitespace characters in Python?
a) isspace()
b) iswhitespace()
c) isblank()
d) isemptyspace()
Reply: a
Clarification: The isspace()
technique returns True
if all characters within the string are whitespace characters, in any other case False
.
Q25. What’s the output of the next Python code snippet?
string = "Howdy, World!"
print(string[::-1])
a) “Howdy, World!”
b) “dlroW ,olleH”
c) “World! Howdy,”
d) “olleH ,dlroW”
Reply: b
Clarification: Slicing with a detrimental step (-1) reverses the string.
a) string[-2]
b) string[2:]
c) string[-2:]
d) string[:-2]
Reply: c
Clarification: Slicing with a detrimental step (-1) reverses the string.
Q27. What’s the output of the next Python code snippet?
string = "Howdy, World!"
print(len(string))
a) 12
b) 13
c) 11
d) 10
Reply: b
Clarification: The len()
perform returns the variety of characters within the string.
Q28. Which technique is used to transform a string to an inventory of characters in Python?
a) break up()
b) checklist()
c) chars()
d) tolist()
Reply: b
Clarification: The checklist()
perform converts the string to an inventory of characters.
Q29. What’s the output of the next Python code snippet?
string = "Howdy, World!"
print(string.capitalize())
a) “good day, world!”
b) “Howdy, world!”
c) “good day, World!”
d) “Howdy, World!”
Reply: d
Clarification: The capitalize()
technique capitalizes the primary character of the string.
Q30. How will you examine if a string is empty in Python?
a) Utilizing the isempty()
technique
b) Utilizing the empty()
technique
c) Utilizing the is_empty()
technique
d) Utilizing the len()
perform
Reply: d
Clarification: Checking the size of the string utilizing the len()
perform is a typical option to examine if a string is empty.
Q31. What does the swapcase()
technique do in Python string manipulation?
a) Swaps the case of all characters within the string
b) Converts the string to uppercase
c) Converts the string to lowercase
d) Swaps the case of the primary character within the string
Reply: a
Clarification: The swapcase()
technique swaps the case of all characters within the string.
Q32. What would be the output of the next Python code snippet?
string = "Howdy, World!"
print(string.partition(","))
a) (‘Howdy’, ‘,’, ‘World!’)
b) (‘Howdy, ‘, ‘World’, ‘!’)
c) (‘Howdy’, ‘World’, ”)
d) (‘Howdy’, ‘, World’, ”)
Reply: a
Clarification: The partition()
technique splits the string into three components primarily based on the primary incidence of the desired separator.
Q33. What does the zfill()
technique do in Python string manipulation?
a) Pads the string with main zeroes to fill the desired width
b) Pads the string with trailing zeroes to fill the desired width
c) Removes all zeroes from the string
d) Converts the string to lowercase
Reply: a
Clarification: The zfill()
technique pads the string with main zeroes to fill the desired width.
Congratulations on finishing the Python String Manipulation MCQ Quiz! String manipulation is a basic ability for any Python programmer, because it lets you work with textual content knowledge successfully. By mastering string manipulation methods in Python, you possibly can carry out numerous duties similar to parsing enter, formatting output, extracting data, and performing textual content processing operations. Hold training and experimenting with Python’s string manipulation functionalities to change into proficient in dealing with strings inside your applications. You probably have any questions or wish to delve deeper into any subject, don’t hesitate to proceed your studying journey. Completely satisfied coding!
You can too enroll in out free Python Course As we speak!
Learn our extra articles associated to MCQs in Python: