MCQ-Strings - GR 10
MCQ-Strings - GR 10
B) A built-in function
C) A mathematical operation
D) A file format
B) r"Hello, World!"
C) 'Hello, World!'
D) "Hello, World!\n"
A) 6
B) 7
C) 5
D) 8
6. Which method is used to convert a string to lowercase in Python?
A) lower()
B) toLower()
C) lowercase()
D) casefold()
7. Which method is used to find the index of the first occurrence of a substring
within a string?
A) find()
B) index()
C) search()
D) both A and B
D) Error
10. Which method is used to remove leading and trailing whitespace from a
string?
A) trim()
B) strip()
C) clean()
D) remove()
D) Reverses a string
14. What will be the output of the code s = "Hello, World!"; print(s[7:])?
A) "Hello, World!"
B) "World!"
C) "World"
D) Error
D) /
C) "PythonPython"
D) Error
D) /
A) format()
B) replace()
C) substitute()
D) insert()
C) 66
D) 'B'
20. Which of the following is a valid way to create a multiline string in Python?
A) "This is a multiline string."
B) 'This is a\nmultiline string.'
B) in()
C) includes()
D) substring()
C) 15
D) 16
23. Which method is used to capitalize the first letter of a string in Python?
A) uppercase()
B) capitalize()
C) firstletter()
D) initcap()
B) "yth"
C) "ytho"
D) "YTH"
A) count()
B) find()
C) search()
D) locate()
B) list()
C) chars()
D) to_list()
28. Which of the following is not a valid way to escape a single quote in a string?
A) \'
B) "
C) \\'
D) ''
A) True
B) False
C) Error
D) None
30. Which method is used to check if all characters in a string are digits?
A) isdigit()
B) isnumber()
C) isalpha()
D) isalnum()
B) Reversing a string
C) Combining two strings
D) Checking if a string is empty
32. In Python, what is the result of the slice s[2:5] for the string s = "Python"?
A) "Pyt"
B) "tho"
C) "thon"
D) "Pyth"
C) An error is raised.
D) The slice includes the entire string.
34. Which slice notation will extract the last three characters from a string s?
A) s[-3:]
B) s[:-3]
C) s[3:]
D) s[-1:-4:-1]
36. In Python, how do you slice a string to get every second character, starting
from the beginning?
A) s[::2]
B) s[1::2]
C) s[1:2]
D) s[2::2]
37. If you want to reverse a string s using slicing, which slice notation would you
use?
A) s[::-1]
B) s[1::-1]
C) s[:-1:-1]
D) s[1:0:-1]
38. What is the result of the slice s[2:8] for the string s = "Python is fun!"?
A) "thon i"
B) "thon is"
C) "thon is "
D) "thon is f"
39. How do you extract a substring from a string that includes characters at
even indices (0, 2, 4, ...)?
A) s[0::2]
B) s[::2]
C) s[1::2]
D) both A and B
40. What will be the output of the code s = "Hello, World!"; s[-7:-1]?
A) "Hello"
B) " World"
C) "World"
D) "lo, Wo"