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!
1. Which of the following is the correct way to concatenate two strings in Python?
a) string1 + string2
b) string1 .concat(string2)
c) string1.concatenate(string2)
d) string1.add(string2)
2. What will be the output of the following code snippet?
string = “Hello World”
print(string[0:5])
a) Hello
b) World
c) Hello World
d) H
3. Which method is used to convert a string to uppercase in Python?
a) upper()
b) toUpperCase()
c) uppercase()
d) to_upper()
4. What will be the output of the following code snippet?
string = “Python is fun”
print(string.replace(“fun”, “awesome”))
a) Python is fun
b) Python is awesome
c) Python is
d) fun is awesome
5. Which method is used to split a string into a list of substrings based on a delimiter?
a) split()
b) divide()
c) separate()
d) break()
6. What will be the output of the following code snippet?
string = “Python”
print(string[::-1])
a) Python
b) nohtyP
c) P
d) n
7. Which method is used to find the index of the first occurrence of a substring in a string?
a) find()
b) search()
c) locate()
d) index()
8. What will be the output of the following code snippet?
string = “Python”
print(string.startswith(“Py”))
a) True
b) False
c) Error
d) None
9. Which method is used to remove leading and trailing whitespaces from a string?
a) strip()
b) trim()
c) remove()
d) delete()
10. What will be the output of the following code snippet?
string = “Python”
print(string.isnumeric())
a) True
b) False
c) Error
d) None
11. Which method is used to check if a string ends with a specified suffix?
a) endswith()
b) ends()
c) finishwith()
d) suffix()
12. What will be the output of the following code snippet?
string = “Python”
print(string.count(“o”))
a) 0
b) 1
c) 2
d) Error
13. Which method is used to check if a string contains only alphabetic characters?
a) isalpha()
b) alphabetic()
c) contains_alpha()
d) only_alpha()
14. What will be the output of the following code snippet?
string = “Python”
print(string.capitalize())
a) python
b) PYTHON
c) Python
d) pYTHON
15. Which method is used to find the length of a string?
a) len()
b) length()
c) size()
d) count()
16. What will be the output of the following code snippet?
string = “Python”
print(string.upper())
a) python
b) PYTHON
c) Python
d) pYTHON
17. Which method is used to check if a string contains a specified substring?
a) find()
b) search()
c) contains()
d) index()
18. What will be the output of the following code snippet?
string = “Python”
print(string.islower())
a) True
b) False
c) Error
d) None
19. Which method is used to replace a specified substring with another string?
a) replace()
b) swap()
c) change()
d) modify()
20. What will be the output of the following code snippet?
string = “Python”
print(string.isupper())
a) True
b) False
c) Error
d) None
21. Which method is used to check if a string contains only numeric characters?
a) isnumeric()
b) numeric()
c) contains_numeric()
d) only_numeric()
22. What will be the output of the following code snippet?
string = “Python”
print(string.find(“th”))
a) 0
b) 1
c) -1
d) Error
23. Which method is used to check if a string starts with a specified prefix?
a) startswith()
b) starts()
c) beginwith()
d) prefix()
24. What will be the output of the following code snippet?
string = “Python”
print(string.split())
a) [‘Python’]
b) [‘P’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’]
c
- SEO Powered Content & PR Distribution. Get Amplified Today.
- PlatoData.Network Vertical Generative Ai. Empower Yourself. Access Here.
- PlatoAiStream. Web3 Intelligence. Knowledge Amplified. Access Here.
- PlatoESG. Carbon, CleanTech, Energy, Environment, Solar, Waste Management. Access Here.
- PlatoHealth. Biotech and Clinical Trials Intelligence. Access Here.
- Source: Plato Data Intelligence.
- Source Link: https://zephyrnet.com/30-mcqs-on-python-string-manipulation/