Q1. Which data type is used to store text in Python?
✅ Correct Answer: (C) str
📘 Explanation: Python uses the str data type to store text.
📘 Explanation: Python uses the str data type to store text.
Q2. Which of the following is the correct way to create a string?
✅ Correct Answer: (A) ‘Hello’
📘 Explanation: Strings must be enclosed in quotes.
📘 Explanation: Strings must be enclosed in quotes.
Q3. Which operator is used to concatenate strings?
✅ Correct Answer: (B) +
📘 Explanation: The + operator joins strings.
📘 Explanation: The + operator joins strings.
Q4. Which operator is used to repeat a string?
✅ Correct Answer: (B) *
📘 Explanation: The * operator repeats a string.
📘 Explanation: The * operator repeats a string.
Q5. What is the output of the following code?
print("Python"[0])
✅ Correct Answer: (A) P
📘 Explanation: Indexing starts from 0 in Python.
📘 Explanation: Indexing starts from 0 in Python.
Q6. Which function returns the length of a string?
✅ Correct Answer: (C) len()
📘 Explanation: len() returns the number of characters.
📘 Explanation: len() returns the number of characters.
Q7. What is the output of “Hello”[1:4]?
✅ Correct Answer: (B) ell
📘 Explanation: Slicing starts from index 1 up to (but not including) 4.
📘 Explanation: Slicing starts from index 1 up to (but not including) 4.
Q8. Which method converts a string to uppercase?
✅ Correct Answer: (A) upper()
📘 Explanation: upper() converts all characters to uppercase.
📘 Explanation: upper() converts all characters to uppercase.
Q9. Which method removes whitespace from both ends of a string?
✅ Correct Answer: (B) strip()
📘 Explanation: strip() removes leading and trailing spaces.
📘 Explanation: strip() removes leading and trailing spaces.
Q10. What will be the output of the following code?
print("Python".lower())
✅ Correct Answer: (B) python
📘 Explanation: lower() converts all letters to lowercase.
📘 Explanation: lower() converts all letters to lowercase.
Q11. Which method is used to replace a substring?
✅ Correct Answer: (B) replace()
📘 Explanation: replace(old, new) replaces occurrences.
📘 Explanation: replace(old, new) replaces occurrences.
Q12. Which method splits a string into a list?
✅ Correct Answer: (C) split()
📘 Explanation: split() divides a string into list elements.
📘 Explanation: split() divides a string into list elements.
Q13. Which of the following is an immutable object?
✅ Correct Answer: (C) string
📘 Explanation: Strings cannot be changed after creation.
📘 Explanation: Strings cannot be changed after creation.
Q14. What is the output of “abc” * 3?
✅ Correct Answer: (A) abcabcabc
📘 Explanation: * repeats the string.
📘 Explanation: * repeats the string.
Q15. Which method checks if a string starts with a specific substring?
✅ Correct Answer: (C) startswith()
📘 Explanation: startswith() checks prefix.
📘 Explanation: startswith() checks prefix.
Q16. Which method checks if all characters are digits?
✅ Correct Answer: (B) isdigit()
📘 Explanation: isdigit() returns True if all characters are digits.
📘 Explanation: isdigit() returns True if all characters are digits.
Q17. What is the output of the following code?
print("Hello".find("e"))
✅ Correct Answer: (B) 1
📘 Explanation: find() returns the index of first occurrence.
📘 Explanation: find() returns the index of first occurrence.
Q18. Which method converts the first character to uppercase?
✅ Correct Answer: (B) capitalize()
📘 Explanation: capitalize() capitalizes the first letter.
📘 Explanation: capitalize() capitalizes the first letter.
Q19. Which operator is used to check substring presence?
✅ Correct Answer: (A) in
📘 Explanation: in checks membership in a string.
📘 Explanation: in checks membership in a string.
Q20. What is the output of the following code?
print("Python"[-1])
✅ Correct Answer: (B) n
📘 Explanation: Negative indexing accesses elements from the end.
📘 Explanation: Negative indexing accesses elements from the end.