0% found this document useful (0 votes)
90 views9 pages

MCQ-Strings - GR 10

Uploaded by

2stoospectacular
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views9 pages

MCQ-Strings - GR 10

Uploaded by

2stoospectacular
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

1. What is a string in Python?

A) A data type for storing characters

B) A built-in function
C) A mathematical operation
D) A file format

2. Which of the following is not a valid way to create a string in Python?

A) Using single quotes ('string')


B) Using double quotes ("string")

C) Using triple quotes ('''string''')


D) Using square brackets ([string])

3. How do you access an individual character in a string in Python?


A) Using the charAt() method

B) Using square brackets and an index value


C) Using the substr() method
D) Using the substring() method

4. Which of the following strings is considered a raw string in Python?


A) "Hello, World!"

B) r"Hello, World!"
C) 'Hello, World!'

D) "Hello, World!\n"

5. What will be the output of the following code: len("Python")?

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

8. What is the result of the expression "Python" + " is fun!"?


A) "Python is fun!"
B) "Pythonisfun!"
C) "Python + is fun!"

D) Error

9. How do you check if a string contains only alphabetic characters?


A) isalpha()
B) isnumeric()
C) isdigit()
D) isalnum()

10. Which method is used to remove leading and trailing whitespace from a
string?
A) trim()

B) strip()
C) clean()
D) remove()

11. What does the split() method in Python do?


A) Splits a string into a list of characters
B) Splits a string into a list of words
C) Removes spaces from a string

D) Reverses a string

12. Which method is used to replace all occurrences of a substring in a string?


A) replace()
B) sub()
C) swap()
D) modify()

13. What does the join() method do in Python?


A) Concatenates two strings
B) Joins elements of a list into a single string
C) Splits a string into a list
D) Finds the intersection of two strings

14. What will be the output of the code s = "Hello, World!"; print(s[7:])?

A) "Hello, World!"
B) "World!"
C) "World"

D) Error

15. Which operator is used for string concatenation in Python?


A) +
B) -
C) *

D) /

16. What will be the result of "Python" * 3?


A) "PythonPythonPython"
B) "Python3"

C) "PythonPython"
D) Error

17. Which operator is used for string concatenation in Python?


A) *
B) -
C) +

D) /

18. Which method is used to format a string by replacing placeholders with


values?

A) format()
B) replace()
C) substitute()
D) insert()

19. What is the result of the expression ord('A')?


A) 65
B) 'A'

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.'

C) '''This is a\nmultiline string.'''


D) "This is a multiline string."

21. Operator used to check if a string contains a specific substring in Python?


A) contains()

B) in()
C) includes()

D) substring()

22. What is the result of the expression len("Python is easy!")?


A) 13
B) 14

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()

24. How do you reverse a string in Python?


A) Using the reverse() method

B) Using the revert() method


C) Using slicing with a negative step

D) Using the invert() function


25. What will be the output of the code s = "Python"; s[1:4]?
A) "P"

B) "yth"
C) "ytho"
D) "YTH"

26. Which method is used to count the occurrences of a substring in a string?

A) count()
B) find()

C) search()
D) locate()

27. How do you convert a string to a list of characters in Python?


A) split()

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) ''

29. What is the result of the expression "abc" < "xyz"?

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()

31. What is string slicing in Python?


A) Extracting substrings from a string

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"

33. If you omit the start index in a slice, what happens?

A) The slice starts from the beginning of the string.


B) The slice starts from the end of the string.

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]

35. What is the output of the code s = "Python is great!"; s[::-1]?


A) "!taerg si nohtyP"
B) "taerg si nohtyP!"
C) "great is Python!"
D) "!taerg si nohtyP "

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"

You might also like