{"id":2608331,"date":"2024-02-19T07:10:10","date_gmt":"2024-02-19T12:10:10","guid":{"rendered":"https:\/\/platoai.gbaglobal.org\/platowire\/a-comprehensive-collection-of-30-multiple-choice-questions-on-python-string-manipulation\/"},"modified":"2024-02-19T07:10:10","modified_gmt":"2024-02-19T12:10:10","slug":"a-comprehensive-collection-of-30-multiple-choice-questions-on-python-string-manipulation","status":"publish","type":"platowire","link":"https:\/\/platoai.gbaglobal.org\/platowire\/a-comprehensive-collection-of-30-multiple-choice-questions-on-python-string-manipulation\/","title":{"rendered":"A Comprehensive Collection of 30+ Multiple Choice Questions on Python String Manipulation"},"content":{"rendered":"

\"\"<\/p>\n

Python String Manipulation is a fundamental concept that every Python programmer should be familiar with. It involves various operations that can be performed on strings, such as concatenation, slicing, formatting, and searching. To test your knowledge on this topic, we have compiled a comprehensive collection of 30+ multiple-choice questions. Let’s dive in!<\/p>\n

1. Which of the following is the correct way to concatenate two strings in Python?
\na) string1 + string2
\nb) string1 .concat(string2)
\nc) string1.concatenate(string2)
\nd) string1.add(string2)<\/p>\n

2. What will be the output of the following code snippet?<\/p>\n

string = “Hello World”
\nprint(string[0:5])<\/p>\n

a) Hello
\nb) World
\nc) Hello World
\nd) H<\/p>\n

3. Which method is used to convert a string to uppercase in Python?
\na) upper()
\nb) toUpperCase()
\nc) uppercase()
\nd) to_upper()<\/p>\n

4. What will be the output of the following code snippet?<\/p>\n

string = “Python is fun”
\nprint(string.replace(“fun”, “awesome”))<\/p>\n

a) Python is fun
\nb) Python is awesome
\nc) Python is
\nd) fun is awesome<\/p>\n

5. Which method is used to split a string into a list of substrings based on a delimiter?
\na) split()
\nb) divide()
\nc) separate()
\nd) break()<\/p>\n

6. What will be the output of the following code snippet?<\/p>\n

string = “Python”
\nprint(string[::-1])<\/p>\n

a) Python
\nb) nohtyP
\nc) P
\nd) n<\/p>\n

7. Which method is used to find the index of the first occurrence of a substring in a string?
\na) find()
\nb) search()
\nc) locate()
\nd) index()<\/p>\n

8. What will be the output of the following code snippet?<\/p>\n

string = “Python”
\nprint(string.startswith(“Py”))<\/p>\n

a) True
\nb) False
\nc) Error
\nd) None<\/p>\n

9. Which method is used to remove leading and trailing whitespaces from a string?
\na) strip()
\nb) trim()
\nc) remove()
\nd) delete()<\/p>\n

10. What will be the output of the following code snippet?<\/p>\n

string = “Python”
\nprint(string.isnumeric())<\/p>\n

a) True
\nb) False
\nc) Error
\nd) None<\/p>\n

11. Which method is used to check if a string ends with a specified suffix?
\na) endswith()
\nb) ends()
\nc) finishwith()
\nd) suffix()<\/p>\n

12. What will be the output of the following code snippet?<\/p>\n

string = “Python”
\nprint(string.count(“o”))<\/p>\n

a) 0
\nb) 1
\nc) 2
\nd) Error<\/p>\n

13. Which method is used to check if a string contains only alphabetic characters?
\na) isalpha()
\nb) alphabetic()
\nc) contains_alpha()
\nd) only_alpha()<\/p>\n

14. What will be the output of the following code snippet?<\/p>\n

string = “Python”
\nprint(string.capitalize())<\/p>\n

a) python
\nb) PYTHON
\nc) Python
\nd) pYTHON<\/p>\n

15. Which method is used to find the length of a string?
\na) len()
\nb) length()
\nc) size()
\nd) count()<\/p>\n

16. What will be the output of the following code snippet?<\/p>\n

string = “Python”
\nprint(string.upper())<\/p>\n

a) python
\nb) PYTHON
\nc) Python
\nd) pYTHON<\/p>\n

17. Which method is used to check if a string contains a specified substring?
\na) find()
\nb) search()
\nc) contains()
\nd) index()<\/p>\n

18. What will be the output of the following code snippet?<\/p>\n

string = “Python”
\nprint(string.islower())<\/p>\n

a) True
\nb) False
\nc) Error
\nd) None<\/p>\n

19. Which method is used to replace a specified substring with another string?
\na) replace()
\nb) swap()
\nc) change()
\nd) modify()<\/p>\n

20. What will be the output of the following code snippet?<\/p>\n

string = “Python”
\nprint(string.isupper())<\/p>\n

a) True
\nb) False
\nc) Error
\nd) None<\/p>\n

21. Which method is used to check if a string contains only numeric characters?
\na) isnumeric()
\nb) numeric()
\nc) contains_numeric()
\nd) only_numeric()<\/p>\n

22. What will be the output of the following code snippet?<\/p>\n

string = “Python”
\nprint(string.find(“th”))<\/p>\n

a) 0
\nb) 1
\nc) -1
\nd) Error<\/p>\n

23. Which method is used to check if a string starts with a specified prefix?
\na) startswith()
\nb) starts()
\nc) beginwith()
\nd) prefix()<\/p>\n

24. What will be the output of the following code snippet?<\/p>\n

string = “Python”
\nprint(string.split())<\/p>\n

a) [‘Python’]
\nb) [‘P’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’]
\nc<\/p>\n