Python Strings MCQs | 25 Practice Questions with Answers | CBSE Class 11 Computer Science
Class 11 · Computer Science
Python Strings MCQs (25 Questions)
Practice these multiple-choice questions to strengthen your understanding of Python Strings. Click Show Answer to reveal the correct answer and explanation.
Q1. Which of the following is a valid Python string?
A. 12345
B. "Python"
C. 45.67
D. True
Show Answer
Answer: B. "Python"
Explanation: A string is enclosed within single, double, or triple quotes.
Q2. Which function returns the length of a string?
A. size()
B. length()
C. len()
D. count()
Show Answer
Answer: C. len()
Explanation: The len() function returns the number of characters in a string.
Q3. What is the index of the first character in a Python string?
A. 1
B. -1
C. 0
D. Depends on the string
Show Answer
Answer: C. 0
Explanation: Python uses zero-based indexing.
Q4. Which operator is used to concatenate two strings?
A. *
B. +
C. /
D. %
Show Answer
Answer: B. +
Explanation: The + operator joins two strings.
Q5. Which operator is used to repeat a string?
A. +
B. %
C. *
D. //
Show Answer
Answer: C. *
Explanation: The * operator repeats a string multiple times.
Q6. What is the output of the following code?
text="Python"
print(text[2])
A. P
B. t
C. y
D. h
Show Answer
Answer: B. t
Explanation: Index positions are P=0, y=1, t=2.
Q7. Which slicing expression returns the first three characters of a string text?
A. text[0:2]
B. text[:3]
C. text[3:]
D. text[-3:]
Show Answer
Answer: B. text[:3]
Explanation: The stop index is excluded, so characters at indices 0, 1, and 2 are returned.
Q8. Which method converts all characters of a string to uppercase?
A. upper()
B. capitalize()
C. title()
D. lower()
Show Answer
Answer: A. upper()
Explanation: The upper() method converts all letters to uppercase.
Q9. Which method converts all characters of a string to lowercase?
A. capitalize()
B. title()
C. lower()
D. swapcase()
Show Answer
Answer: C. lower()
Explanation: The lower() method converts all alphabetic characters to lowercase.
Q10. Which method counts the number of occurrences of a substring?
A. index()
B. find()
C. count()
D. replace()
Show Answer
Answer: C. count()
Explanation: The count() method returns the number of occurrences of the specified substring.
Q11. Which method returns the index of the first occurrence of a substring?
A. count()
B. find()
C. replace()
D. split()
Show Answer
Answer: B. find()
Explanation: The find() method returns the index of the first occurrence of a substring. If the substring is not found, it returns -1.
Q12. What does the find() method return if the substring is not found?
A. 0
B. None
C. -1
D. Error
Show Answer
Answer: C. -1
Explanation: Unlike index(), the find() method returns -1 when the substring does not exist.
Q13. Which method raises a ValueError if the substring is not found?
A. find()
B. count()
C. replace()
D. index()
Show Answer
Answer: D. index()
Explanation: The index() method raises a ValueError if the specified substring is absent.
Q14. Which method checks whether a string starts with a specified substring?
A. startswith()
B. endswith()
C. find()
D. split()
Show Answer
Answer: A. startswith()
Explanation: The startswith() method returns True if the string begins with the specified substring.
Q15. Which method checks whether a string ends with a specified substring?
A. startswith()
B. replace()
C. endswith()
D. partition()
Show Answer
Answer: C. endswith()
Explanation: The endswith() method returns True if the string ends with the specified substring.
Q16. Which method returns True only if all characters are alphabets?
A. isdigit()
B. isalpha()
C. isalnum()
D. isspace()
Show Answer
Answer: B. isalpha()
Explanation: The isalpha() method checks whether all characters are alphabetic.
Q17. Which method returns True only if all characters are digits?
A. isdigit()
B. isalpha()
C. isalnum()
D. isnumeric()
Show Answer
Answer: A. isdigit()
Explanation: The isdigit() method returns True only when every character is a digit.
Q18. Which method returns True if a string contains only letters and digits?
A. isalpha()
B. isdigit()
C. isalnum()
D. isspace()
Show Answer
Answer: C. isalnum()
Explanation: The isalnum() method checks for alphanumeric characters only.
Q19. Which method removes spaces from both the beginning and end of a string?
A. lstrip()
B. rstrip()
C. strip()
D. remove()
Show Answer
Answer: C. strip()
Explanation: The strip() method removes leading and trailing whitespace.
Q20. Which method replaces one substring with another?
A. split()
B. join()
C. replace()
D. partition()
Show Answer
Answer: C. replace()
Explanation: The replace() method replaces all occurrences of the specified substring with another substring.
Q21. Which method joins the elements of a list into a single string?
A. split()
B. join()
C. replace()
D. partition()
Show Answer
Answer: B. join()
Explanation: The join() method joins the elements of an iterable using the specified separator.
Q22. Which method converts a string into a list by separating it at a specified delimiter?
A. join()
B. replace()
C. split()
D. strip()
Show Answer
Answer: C. split()
Explanation: The split() method divides a string into a list of substrings based on the specified separator.
Q23. Which method divides a string into three parts based on the first occurrence of a separator?
A. split()
B. replace()
C. partition()
D. join()
Show Answer
Answer: C. partition()
Explanation: The partition() method returns a tuple containing the part before the separator, the separator itself, and the part after the separator.
Q24. Which of the following statements is correct about Python strings?
A. Strings are mutable.
B. Strings can be modified directly.
C. Strings are immutable.
D. Strings cannot be sliced.
Show Answer
Answer: C. Strings are immutable.
Explanation: Once a string is created, its characters cannot be changed. Any modification creates a new string.
Q25. Which loop is commonly used to traverse all characters of a string?
A. while only
B. do-while
C. for loop
D. switch
Show Answer
Answer: C. for loop
Explanation: A for loop is the simplest and most commonly used way to traverse every character in a string.
Answer Key
| Q.No. | Answer | Q.No. | Answer | Q.No. | Answer |
|---|---|---|---|---|---|
| 1 | B | 10 | C | 19 | C |
| 2 | C | 11 | B | 20 | C |
| 3 | C | 12 | C | 21 | B |
| 4 | B | 13 | D | 22 | C |
| 5 | C | 14 | A | 23 | C |
| 6 | B | 15 | C | 24 | C |
| 7 | B | 16 | B | 25 | C |
| 8 | A | 17 | A | ||
| 9 | C | 18 | C |
Practice Tips
- Revise all important string methods before attempting these MCQs.
- Practice writing small Python programs using string functions.
- Understand the difference between
find()andindex(), as well assplit()andpartition(). - Remember that Python strings are immutable.
- Solve the questions without viewing the answers first, then use the explanations to improve your understanding.