Objective Type (MCQs and One-word Answers) – STRINGS in PYTHON
1 .What will be the output of the following code?
s = "Hello, World!"
print(s[7])
a) W b) o c) l d) r
2. Which method is used to convert all characters of a string to uppercase?
a) uppercase() b) toupper() c) upper() d) capitalize()
3.What will be the output of:
s = "CBSE Computer"
print(s[5:13])
a) Computer b) omputer c) CBSEComp d) CComputer
4. The output of: print(len("Class 12")) is:
a) 8 b) 7 c) 9 d) Error
5.Which method returns the index of the first occurrence of a substring?
a) search() b) index() c) find() d) locate()
6. Which of the following is a valid string declaration?
a) s = 'Python" b) s = Python c) s = 'Python' d) s = 'Python"Hello'
7.Which method replaces a string with another string?
a) swap() b) replace() c) update() d) edit()
8.The output of: print("Hello".lower()) is:
a) HELLO b) hello c) Hello d) error
9.What will be the result of print("abc" + "123")?
a) abc123 b) abc 123 c) abc+123 d) error
10. Which function checks if all characters in a string are digits?
a) isdigit() b) isnum() c) isnumeric() d) Both a and c
Short Answer Type Questions
11. Write a Python statement to extract the last 3 characters from a string name.
12. What is the difference between isalpha() and isalnum()?
13. Write a code to count the number of vowels in a given string.
14. How do you check whether a string starts with a specific substring in Python?
15. Write a statement to remove white spaces from the beginning and end of a string.
16. Predict the output:
s = "Python Programming"
print(s[::-1])
17. What does the in operator do in the context of strings? Give an example.
18. Write a Python function to check whether a string is a palindrome.
19. Give output:
text = " Hello Students "
print(text.strip())
20. Write a program to count how many times the word "India" appears in a sentence.
Class 11 Python – String Slicing Assignment (15 Questions)
Given: text = "WelcomeToCBSEClass12"
Use the above string text for all slicing-related questions below.
String Slicing Questions
1. Extract the word Welcome from the string.
2. Extract the word CBSE using positive indexing.
3. Extract the word Class12 using negative indexing.
4. Write a slice that returns the string ToCBSE.
5. Write the slice that extracts characters from index 7 to 10 (inclusive).
6. Write a slice to extract every second character from the full string.
7. Reverse the entire string using slicing.
8. Extract WelcomeTo using slicing.
9. Write a slice to get all characters from index 11 till the end.
10. Write a slice to get all characters from the beginning to index 6 (inclusive).
11. Extract the last 5 characters using negative indexing.
12. Write a slice that skips one character each time starting from index 0.
13. Slice the string to exclude the first 3 and last 3 characters.
14. Extract the word ToCBSEClass using slicing.
15. Write a slicing statement that results in an empty string.
📝 CBSE Class 12 – String Quiz Answers
Objective Type (MCQs and One-word Answers)
1. a) W
➤ Index 7 of "Hello, World!" is 'W'.
2. c) upper()
➤ Converts all characters to uppercase.
3. a) Computer
➤ "CBSE Computer"[5:13] gives "Computer".
4. a) 8
➤ "Class 12" has 8 characters (including space).
5. c) find()
➤ find() returns index of first occurrence or -1 if not found.
6. c) s = 'Python'
➤ Only this is a valid string (enclosed in matching quotes).
7. b) replace()
➤ Replaces occurrences of a substring.
8. b) hello
➤ "Hello".lower() returns 'hello'.
9. a) abc123
➤ String concatenation.
10. d) Both a and c
➤ isdigit() and isnumeric() both check for numeric characters.
Short Answer Type Questions
11. name[-3:]
➤ Extracts last 3 characters.
12. isalpha() checks only alphabets; isalnum() checks alphabets and digits.
13. python
vowels = "aeiouAEIOU"
count = sum(1 for ch in s if ch in vowels)
14. **Use `startswith()` method:**
```python
s.startswith("Hello")
15. **`s.strip()`**
➤ Removes whitespaces from both ends.
16. **Output: `'gnimmargorP nohtyP'`**
➤ Reverse of the string.
17. **Checks for presence:**
```python
"com" in "computer" # True
```
18. ```python
def is_palindrome(s):
return s == s[::-1]
19. Output: 'Hello Students'
➤ Strips leading/trailing spaces.
20. python
CopyEdit
sentence = "India is great. India is diverse."
print(sentence.count("India")) # Output: 2