strings in python mcq with answers | strings in python class 11 mcq | class 11 computer chapter 8 mcq
1. What is the output of `str1[::-1]` if `str1 = 'Hello World!'`?
2. What is the result of `str1[1:5]` if `str1 = 'Hello World!'`?
3. Which of the following methods returns the string with the first letter of every word in uppercase and the rest in lowercase?
4. Which function would you use to find the length of a string `str1`?
5. In Python, what will be the output of `str1[6:]` if `str1 = 'Hello World!'`?
6. What does the slice operation `str1[n:m:k]` do?
7. What will be the output of the following code? `str1 = 'Hello World!' print(str1[-1])`
8. If `str1 = 'Hello World!'`, what will be the result of `str1[2+4]`?
9. Which method returns the string in reverse order?
10. What is the output of `str1[7:2]` if `str1 = 'Hello World!'`?
11. What will the following code print? `str1 = 'hello WORLD!' print(str1.title())`
12. Which of the following is not a valid string method?
13. What does the built-in function `len()` return when applied to a string?
14. Which method would you use to convert all characters of a string to lowercase?
15. If `str1 = 'Hello World!'`, what will `str1.split()` return?
16. What will the following code print? `str1 = 'Hello World!' print(str1.replace('World', 'Everyone'))`
17. What does the `strip()` method do?
18. Which method would you use to check if a string starts with a specific substring?
19. Which function would you use to convert a string to an integer?
20. What will `str1.index('W')` return if `str1 = 'Hello World!'`?
21. How can you iterate over each character in a string using a `for` loop?
22. What will the following code output? `str1 = 'Hello World!' for ch in str1: print(ch, end='')`
23. Which of the following is true about string immutability in Python?
24. Which method would you use to join elements of a list into a string?
25. What will the following code output? `str1 = 'Hello' str2 = 'World' print(str1 + str2)`
26. Which method would you use to find if a string contains only digits?
27. What will the following code print? `str1 = 'Hello World!' print(str1.count('o'))`
28. What is the output of `str1.find('o')` if `str1 = 'Hello World!'`?
29. Which of the following methods will return the position of the first occurrence of a substring?
30. What will the following code print? `str1 = 'Hello World!' print(str1.upper())`
31. Which method can be used to replace parts of a string with another string?
32. What is the result of `str1.split(',')` if `str1 = 'apple,banana,grape'`?
33. How can you concatenate strings in Python?
34. What does the `format()` method do in Python strings?
35. Which of the following methods checks if all characters in a string are alphanumeric?
36. What will the following code print? `str1 = 'Hello World!' print(str1.swapcase())`
37. Which method would you use to pad a string with zeros on the left?
38. What will `str1.rfind('l')` return if `str1 = 'Hello World!'`?
39. What does the `partition()` method do?
40. What is the result of `str1.isupper()` if `str1 = 'HELLO WORLD!'`?
41. Which method returns `True` if a string contains only whitespace characters?
42. What will the following code print? `str1 = 'Hello World!' print(str1.center(20, '*'))`
43. Which method can be used to check if all characters in the string are lowercase?
44. Which method removes characters from both ends of a string?

No comments: