London Escorts sunderland escorts 1v1.lol unblocked yohoho 76 https://www.symbaloo.com/mix/yohoho?lang=EN yohoho https://www.symbaloo.com/mix/agariounblockedpvp https://yohoho-io.app/ https://www.symbaloo.com/mix/agariounblockedschool1?lang=EN
5.6 C
New York
Tuesday, February 4, 2025

30+ MCQs on Python String Manipulation


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 robust 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 appropriate reply. Take your time to fastidiously learn every query and select the best choice. Let’s discover the world of Python string manipulation collectively!

Python String Manipulation

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() methodology converts all characters within the string to uppercase.

Q2. How are you going to concatenate two strings in Python?

a) Utilizing the concat() methodology

b) Utilizing the be a part of() methodology

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 fall. Which methodology is used to separate a string into a listing of substrings based mostly on a delimiter in Python?

a) cut up()

b) substring()

c) separate()

d) divide()

Reply: a

Clarification: The cut up() methodology is used to separate a string into a listing of substrings based mostly on a delimiter.

Q5. What does the strip() methodology 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() methodology removes main and trailing whitespace characters from the string.

Q6. How are you going to test if a string accommodates a selected substring in Python?

a) Utilizing the accommodates() methodology

b) Utilizing the in key phrase

c) Utilizing the search() perform

d) Utilizing the hasSubstring() methodology

Reply: b

Clarification: The in key phrase is used to test if a substring exists inside a string in Python.

Q7. What does the change() methodology 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 change() methodology 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() methodology right-aligns the string in a subject of width 20 by padding it with areas on the left.

Q9. Which methodology 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() methodology returns the index of the primary incidence of a substring within the string, or -1 if the substring is just not discovered.

Q10. What does the isdigit() methodology 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() methodology 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.cut up(","))

a) [“Hello”, “World!”]

b) [“Hello,”, “World!”]

c) [“Hello”]

d) [“World!”]

Reply: a

Clarification: The cut up() methodology splits the string into a listing of substrings based mostly on the desired delimiter (, on this case).

Q12. How are you going to test if a string begins with a selected substring in Python?

a) Utilizing the startswith() methodology

b) Utilizing the beginwith() methodology

c) Utilizing the begin() methodology

d) Utilizing the isstart() methodology

Reply: a

Clarification: The startswith() methodology is used to test if a string begins with a selected substring in Python.

Q13. What does the be a part of() methodology do in Python string manipulation?

a) Joins the weather of a listing right into a single string

b) Splits the string into a listing of substrings

c) Reverses the string

d) Converts the string to uppercase

Reply: a

Clarification: The be a part of() methodology joins the weather of a listing right into a single string utilizing the desired delimiter.

Q14. How are you going to take away main whitespace characters from a string in Python?

a) Utilizing the trim() methodology

b) Utilizing the remove_leading_whitespace() methodology

c) Utilizing the lstrip() methodology

d) Utilizing the strip() methodology

Reply: c

Clarification: The lstrip() methodology removes main whitespace characters from the string.

Q15. Which methodology 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() methodology converts the primary character of a string to uppercase.

Q16. How are you going to test if a string ends with a selected substring in Python?

a) Utilizing the endwith() methodology

b) Utilizing the isend() methodology

c) Utilizing the endswith() methodology

d) Utilizing the isendwith() methodology

Reply: c

Clarification: The endswith() methodology is used to test if a string ends with a selected 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() methodology returns the index of the primary incidence of a substring within the string, or -1 if the substring is just not discovered.

Q18. Which methodology 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() methodology is used to transform all characters in a string to lowercase.

Q19. What does the isalpha() methodology 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 accommodates any non-alphanumeric characters

Reply: a

Clarification: The isalpha() methodology 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.change("World", "Python"))

a) “Howdy, Python!”

b) “Howdy, World!”

c) “Python, World!”

d) “Python, Python!”

Reply: a

Clarification: The change() methodology replaces all occurrences of a substring with one other substring within the string.

Q21. How are you going to test if all characters in a string are digits in Python?

a) Utilizing the isdigit() methodology

b) Utilizing the isnumeric() methodology

c) Utilizing the isnumber() methodology

d) Utilizing the all_digits() methodology

Reply: a

Clarification: The isdigit() methodology returns True if all characters within the string are digits, in any other case False.

Q22. What does the title() methodology 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() methodology 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() methodology removes main and trailing whitespace characters from the string.

Q24. Which methodology is used to test if a string accommodates solely whitespace characters in Python?

a) isspace()

b) iswhitespace()

c) isblank()

d) isemptyspace()

Reply: a

Clarification: The isspace() methodology 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 destructive step (-1) reverses the string.

a) string[-2]

b) string[2:]

c) string[-2:]

d) string[:-2]

Reply: c

Clarification: Slicing with a destructive 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 methodology is used to transform a string to a listing of characters in Python?

a) cut up()

b) checklist()

c) chars()

d) tolist()

Reply: b

Clarification: The checklist() perform converts the string to a listing of characters.

Q29. What’s the output of the next Python code snippet?

string = "Howdy, World!"
print(string.capitalize())

a) “hiya, world!”

b) “Howdy, world!”

c) “hiya, World!”

d) “Howdy, World!”

Reply: d

Clarification: The capitalize() methodology capitalizes the primary character of the string.

Q30. How are you going to test if a string is empty in Python?

a) Utilizing the isempty() methodology

b) Utilizing the empty() methodology

c) Utilizing the is_empty() methodology

d) Utilizing the len() perform

Reply: d

Clarification: Checking the size of the string utilizing the len() perform is a standard strategy to test if a string is empty.

Q31. What does the swapcase() methodology 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() methodology 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() methodology splits the string into three components based mostly on the primary incidence of the desired separator.

Q33. What does the zfill() methodology 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() methodology 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 strategies in Python, you’ll be able to carry out numerous duties similar to parsing enter, formatting output, extracting data, and performing textual content processing operations. Preserve training and experimenting with Python’s string manipulation functionalities to change into proficient in dealing with strings inside your packages. When you have any questions or need to delve deeper into any matter, don’t hesitate to proceed your studying journey. Joyful coding!

You can even enroll in out free Python Course Right now!

Learn our extra articles associated to MCQs in Python:

Related Articles

Social Media Auto Publish Powered By : XYZScripts.com