0% found this document useful (0 votes)
5 views11 pages

MCQ On Python String - Qns

The document contains a series of multiple-choice questions (MCQs) focused on string manipulation in Python. Each question tests knowledge on string properties, operations, and functions, providing options for answers. The questions cover a wide range of topics including string indexing, methods, and error types related to string operations.
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)
5 views11 pages

MCQ On Python String - Qns

The document contains a series of multiple-choice questions (MCQs) focused on string manipulation in Python. Each question tests knowledge on string properties, operations, and functions, providing options for answers. The questions cover a wide range of topics including string indexing, methods, and error types related to string operations.
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

MCQ ON STRING MANIPULATION

Q1. Following is an example of ___________________


sv = “[Link]”
a. List b. String c. Dictionary d. None of the above

Q2. Python considered the character enclosed in triple quotes as String.(T/F)


a. True b. False

Q3. Write the output of the following.


a = "Blog"
a ='a'
print(a)
a. Bloga b. aBlog c. Blog d. a

Q4. Write the output of the following:


a="We\nto my \nb\t ok"
print(a)
a. b. c. d. None of the above
We We Weto
to my to myb o my
b ok b ok

Q5. Write the output of the following code :


a= "Welcome to \"my\" blog"
print(a)
a. Welcome to “my” blog b. Welcome to \”my\” blog
c. Error d. None of the above

Q6. Write the output of the following code :


a= "Welcome to \
blog"
print(a)
a. Welcome to blog b. c. d. Error
Welcome to \ Welcome to
blog blog

Q7. Write the output of the following code :


str = "Welcome"
str[2] = 'a'
print(str)
a. Weacome b. Error c. aWelcome d. Welcomea

Q8. Write the output of the following code :


str = "Welcome"
l=len(str)
print(l)
a. 6 b. 7 c. 8 d. Error

Q9. What we call the following:


\n
\t
Q10. Write the output of the following code :
a = '''A
B
C'''
print(a)
a. ABC b. c. d. Error
A A
BC B
C
Q11. What is the index value of ‘i’ in string “Learning”
a. 5 b. 3 c. 6 d. 7

Q12. Index value in String should be of type ________________


a. Float b. Integer c. String d. Boolean

Q13. What type of error is returned by the following :


str = "Learning"
print(str[10])
a. Error in Index b. Index out of range in string
c. IndexError d. None of the above

Q14. Which character will have same index value when you access elements from the beginning
and from the end(ignore the negative sign) in the following string.
s = “Welcome to my blog”
a. ‘t’ b. ‘ ‘ c. ‘o’ d. ‘t’

Q15. String traversal can be done using ‘for’ loop only.(T/F)

Q16. Which of the following statement is correct in accessing each element of string?
a)
a="Learning"
while(i):
print(i)
b)
a="Learning"
for i in a:
print(i)
a. a only b. b only c. both a and b d. None of the above

Q17. Name the function which is used to find length of string.


a. length( ) b. len( ) c. strlen( ) d. slen( )

Q18. Write the output of the following code :


for i in "STR":
print(i)
a. b. c. d.
S STR S T R S
TR T
R
Q19. Write the output of the following code :
a="Learn"
while(a):
print(a)
a. b. Error c. Infinite Loop d. Learn
L
e
a
r
n

Q20. Which operator is used with integers as well as with strings?


a. / b. // c. ** d. *

Q21. Write the output of the following:


2 + '3'
a. 2 3 b. 23 c. SyntaxError d. TypeError
Q22. Which operator is used for string concatenation?
a. * b. // c. + d. –

Q23. Write the output of the following code :


for i in (1,2,3):
print("@" * i)
a. Error b. @@@@@@ c. @ d. @ @ @ @ @ @
@@
@@@

Q24. How many operators are used in the following statement?


7 + 4 * 8 // 2 ** 2 - 6 / 1
a. 5 b. 6 c. 7 d. 8

Q25. Write the output of the following code :


s="blog"
for i in range(-1,-len(s),-1):
print(s[i],end="$")
a. g$o$l$b$ b. g$o$l$ c. Error d. None of the above

Q26. Write the output of the following code :


s= "str"
s1 = "string"
print(s1 in s)
a. True b. False c. Error d. None of the above

Q27. Write the output of the following code :


print("Amita" > "amit")
a. True b. False c. Error d. None of the above

Q28. What is the ASCII value of “A”?


a. 97 b. 66 c. 65 d. 96

Q29. Write the output of the following code :


print("Str"[1:2])
a. t b. No Output c. Error d. None of the above

Q30. Write the output of the following code :


for i in range(65,70):
print(chr(i))
a. Error b. TypeError c. A d. ABCDE
B
C
D
E

Q31. Write the output of the following:


print(“A#B#C#D#E”.split(“#”,2))
a. [‘A’, ‘B’, ‘C#D#E’] b. [‘A#’, ‘B#’, ‘C#D#E’]
c. [‘A’, ‘B’, ‘C’ , ‘D’ , ‘E’] d. Error

Q32. Write the output of the following:


print(“A#B#C#D#E”.replace(“#”,”?”))
a. A#B#C#D#E b. A?B?C?D?E
c. Can not replace as Strings are immutable d. Error
Q33. Write the output of the following:
print(“I love my Country”.find(“o”,4))
a. 3 b. 12 c. 11 d. 3,11

Q34. Write the output of the following.


print(‘#’.join(“12345”))
a. #12345 b. #12345# c. 1#2#3#4#5 d. 1#2#3#4#5#

Q35. Which of the following is not a String built in functions?


a. isupper( ) b. lower( ) c. partition( ) d. swapcases( )

Q36. Write the output of the following:


for i in range(91,100):
if chr(i)=='a':
pass
else:
print(i)
a. b. c. d. Error
91 91 91
92 92 92
93 93 93
94 94 94
95 95 95
96 96 96
97 98
98 99
99

Q37. Write the output of the following:


print(len("\\\\\\///"))
a. 9 b. Error c. 3 d. 6

Q38. Which of the following function returns the ASCII/Unicode value character?
a. asc( ) b. ord( ) c. asci( ) d. ascii( )

Q39. Which of the following statements will also return the same result as given statement?
print(“Computer” + “Computer”)
a. print(“Computer” , ” “, “Computer”) b. print(“Computer”,”Computer”)
c. print(“Computer” **2) d. print(“Computer” * 2)

Q40. Write the output of the following:


for i in range(len("python"),12,2):
print("python"[i-6])
a. b. c. d.

p p y p
t y h y
o t n t
h h
o
n

Q41. Which of the following is a mapping data type?


a. String b. List c. Tuple d. Dictionary
Q42. A _____________ can be created by enclosing one or more characters in single, double or
triple quote.
a. String b. List c. Tuple d. Dictionary

Q43. Characters in a string can be _________ enclosed in quotes.


a. Digits b. white space c. letter d. All of the above

Q44. Each individual character in a string can be accessed using a technique called ____________
a. Indexing b. Replication c. Concatenation d. None of the above

Q45. If we give index value out of the range then we get an ___
a. ValueError b. SyntaxError c. IndexError d. Error

Q46. The index of the first character ____________ on the string is 0

a. from left b. from right c. from middle d. none of the above

Q47. What type of error is returned by statement :

>>> str[1.5]
a. SyntaxError b. ValueError c. IndexError d. TypeError

Q48. Write the output of the following.


str = “python”
print(str[2+1])
a. t b. h c. th d. Error

Q49. Content of string can not be changed, it means that string is


a. mutable b. immutable c. reversible d. none of the above

Q50. What type of error is returned by following code:


>>> str1 = “Hello World!”
>>> str1[1] = ‘a’
a. TypeError b. SyntaxError c. ValueError d. NoError

Q51. Python allows _____________ operations on string data type.


a. Concatenation b. Membership c. Slicing d. All of the above

Q52. Write the output of the following.


>>> str1 = ‘Hello World!’
>>> ‘W’ in str1
a. True b. False c. No d. None of the above

Q53. _____________ method is used to access some part of a string or substring.


a. Slicer b. Slicing c. Membership d. None of the above

Q54. str1[n:m] returns all the characters starting from str1[n] till str1[m-1].(T/F)
a. True b. False

Q55. str[5 : 11] will return ___________ characters.


a. 5 b. 6 c. 11 d. None of the above

Q56. str[11 : 5] will return ____________


a. empty string b. complete string
c. string of six characters d. None of the above

Q57. str[ : ] will return _______________


a. empty string b. Complete String c. Partial String d. Error
Q58. Slice operation can also take a third parameter that specifies the ________
a. Starting index b. Ending index c. Step Size d. None of the above

Q59. Which of the following is correct slicing operation to extract every kth character from the
string str1 starting from n and ending at m-1.
a. str1[: : k] b. str1[n : m+1 : k] c. str1[n : m : k ] d. str1[m : n : k ]

Q60. Which of the following will return reverse string str1?


a. str1[ : : -1] b. str1[: : 1] c. str1[: -1 : -1 ] d. None of the above

Q61 We can access each character of a string or traverse a string using _______________
a. for loop only b. while loop only
c. both of the above d. conditional statement

Q62. Which of the following function returns the string with first letter of every word in the
string in uppercase and rest in lowercase?
a. swapcase( ) b. upper( ) c. title( ) d. capitalize( )

Q63. Write the output of the following:


s = ” Hello”
print([Link](‘a’))
a. 0 b. -1 c. 1 d. Error

Q64. What index value is returned by the following code?


s = “Hello”
print([Link](‘l’))
a. 2 b. 3 c. 4 d. -2

Q65. Following code will return ?


s = “Hello”
print([Link](‘l’,2,5))
a. 2 b. 3 c. 1 d. none of the above

Q66. Name a function which is same as find() but raises an exception if the substring is not
present in the given string.
a. index( ) b. endswith( ) c. startswith( ) d. count( )

Q67. Write the output of the following.


str1 = ‘Hello World! Hello
[Link](‘Hee’)
a. 0 b. -1 c. Error d. None of the above

Q68. Write the output of the following.


>>> str1 = ‘Hello World!’
>>> [Link](‘World!’)
a. True b. False c. Yes d. Error

Q69. Write the output of the following.


s = “hello 123”
print([Link]())
a. False b. True c. Error d. None of the above

Q70. Write the output of the following :


str1 = ‘HelloWorld!!’
[Link]()
a. False b. True c. Error d. None of the above
Q71. Write the output of the following:
str1 = 'hello WORLD!'
[Link]()
a. HELLO world b. Hello World c. Hello world d. HeLlO WoRlD

Q72. Write the output of the following :


>>> str1 = 'Hello World! Hello Hello'
>>> [Link]('Hello',12,25)
a. 1 b. 2 c. 3 d. 4

Q73. Write the output of the following :


>>> str1 = 'Hello World! Hello Hello'
>>> [Link]('Hello')
a. 1 b. 2 c. 3 d. 4

Q74. Write the output of the following :


print("Absbcbcgdbc".count("b",4))
a. 1 b. 2 c. 3 d. 4

Q75. Write the output of the following :


print("Absbcbcgdbc".find("b",5))
a. 1 b. 2 c. 5 d. 6

Q76. Which of the following function returns the index value of first occurrence of substring
occurring in the given string.
a. index( ) b. find( ) c. Both of the above d. None of the above

Q77. find( ) function returns ___________ if the substring is not present in the given string
a. 0 b. 1 c. -1 d. Error

Q78. index( ) function returns _______________ if the substring is not present in the given string
a. 0 b. 1 c. -1 d. Error

Q79. >>> “Hey!”.endswith(‘!’) will return _____________________


a. True b. False c. Error d. None of the above

Q80. Which of the function returns Boolean value?


a. find( ) b. index( ) c. endwith( ) d. endswith( )

Q81. Write the output of the following:


>>> str1 = 'String MCQ'
>>> [Link]('Str')
a. True b. False c. Yes d. No

Q82. Write the output of the following:


print("Welcome-Python".isalnum())
a. True b. False c. Yes d. No

Q83. Write the output of the following:


print(str("WelcomePython".isalnum()).upper())
a. TRUE b. True c. FALSE d. Error

Q84. Write the output of the following:


>>> str1 = 'hello ??'
>>> [Link]( )
a. No b. True c. False d. Error
Q85. Which of the following function returns True if the string is non-empty and has all
uppercase alphabets.
a. islower( ) b. isupper( ) c. Islower( ) d. istitle

Q86. Write the output of the following:


>>> str1 = 'Hello World!'
>>> [Link]('o' , '*')
a. ‘Hello World!’ b. ‘Hell* W*rld!’ c. ‘Hello W*rld!’ d. Error

Q87. Write the output of the following:


>>> str1 = 'India is a Great is Country'
>>> [Link]('is')
a. (‘India ‘, ‘is’, ‘ a Great is Country’) b. (‘India ‘, ‘is’, ‘a Great’, ‘is’, ‘Country’)
c. (‘India ‘, ‘is’, ‘ a Great Country’) d. Error

Q88. Write the output of the following:


str = "Amit is a is a"
s = [Link]('is')
print(s[1])
a. is a b. a c. is d. i

Q89. partition( ) function of string in python return the result in the form of _________________
a. String b. List c. Tuple d. Dictionary

Q90. partition() function divides the main string into ________ substring.
a. 1 b. 2 c. 3 d. 4

Q91. split( ) function returns the _______________of words delimited by the specified substring.
a. List b. Tuple c. Dictionary d. None of the above

Q92. If no delimiter is given in split( ) function then words are separated by ____________
a. space b. colon c. semi colon d. None of the above

Q93. Write the output of the following:


"python".join("@")
a. ‘p@y@t@h@o@n’ b. ‘p@y@t@h@o@n@’
c. ‘@p@y@t@h@o@n@’ d. ‘@’

Q94. Write the output of the following:


"@".join("python")
a. ‘p@y@t@h@o@n’ b. ‘p@y@t@h@o@n@’
c. ‘@p@y@t@h@o@n@’ d. ‘@’

Q95. Write the output of the following:


>>> len(" python".lstrip()) #2 spaces are given before "python"
a. 5 b. 6 c. 7 d. 8

Q96. Which of the following function removes only leading spaces from the string?
a. strip( ) b. lstrip( ) c. rstrip( ) d. Lstrip( )

Q97. Which of the following function can take maximum three arguments/parameters?
a. find( ) b. index( ) c. count( ) d. All of the above

Q98. Which of the following function return the integer value?


a. lower( ) b. upper( ) c. islower( ) d. find( )

Q99. Which of the following is not an inbuilt function of string?


a. length( ) b. find( ) c. endswith( ) d. split( )
Q100. Which function in the following statement will execute first?
print("amit".lower().upper())
a. print( ) b. lower( ) c. upper( ) d. None of the above

Q101. Which function in the following statement will execute last?


print("amit".lower().upper())
a. print( ) b. lower( ) c. upper( ) d. None of the above

Q102. Write the output of the following:


print('aisabisacisadisae'.split('isa',3))
a. [‘a’, ‘b’, ‘c’, ‘disae’] b. [‘a’, ‘b’, ‘cisadisae’]
c. [‘a’, ‘b’, ‘c’, ‘d’, ‘e’] d. None of the above

Q103. Write the output of the following:


print('aisabisacisadisae'.split('isa'))
a. [‘a’, ‘b’, ‘c’, ‘disae’] b. [‘a’, ‘b’, ‘cisadisae’]
c. [‘a’, ‘b’, ‘c’, ‘d’, ‘e’] d. None of the above

Q104. print(“aNd&*”.swapcase()) will display ________________


a. AnD*& b. AnD&* c. aNd&* d. Error

Q105. Write the output of the following:


print('hash-tag'.title())
a. HashTag b. Hash-tag c. Hash-Tag d. Error

Q106. Fill in the blank given below to get output – “amit is a g@@d boy”
print('amit is a good boy'.replace('o', '@', _________ ))
a. 0 b. 1 c. 2 d. Nothing

Q107. print(‘Welcome TO My Blog’.istitle()) will display ________________


a. True b. False c. Error d. None of the above

Q108. print(‘Welcome TO My Blog'[2:6]) will display __________


a. lcom b. lcome c. lco d. None of the above

Q109. print(‘Welcome TO My Blog'[2:6] + ‘Welcome TO My Blog'[5:9]) will display ___


a. lcomme T b. lcomme c. lcomme To d. None of the above

Q110. print(“WZ-1,New Ganga Nagar,New Delhi”.rfind(‘New’)) will display _____


a. 21 b. 5 c. 22 d. 4

Q111. Which of the following statement will return error?


a. print(“Hello” + “Bye”) b. print(“Hello” + “123”)
c. print(“Hello” + 123) d. print(“456” + “123”)

Q112. print(ord(“A”)) will return ___


a. integer value b. string value
c. list d. tuple
Q113. Write the output of the following:
s="str"
for i in s:
if [Link]():
print([Link]()
a. b. STR c. d. None of the above

S STR
T STR
R STR
Q114. Write the output of the following:
s="str"
for i in range(len(s)):
s=[Link]()
print([Link]() + str([Link]()))
a. b. c. d. Error

STRFalse STRFalse STRTrue


STRFalse STRFalse STRTrue
STRFalse STRTrue

Q115. Select the wrong option in reference to the statement given below:
(operand1) * (operand2) = No error
a. Both operands can be of type integer
b. operand1 can be of type integer and operand2 can be of type string
c. operand1 can be of type string and operand2 can be of type integer
d. Both operands can be of type string

Q116. print(“a” in “amit”) will return _________________


a. Integer value b. String value c. Boolean value d. None of the above

Q117. >>>chr(97) will return ________________


a. A b. a c. B d. b

Q118. Write the output of the following:


>>> s = "i love my country"
>>> r = "i love my class"
>>> s[2:5] + s[-7:]
a. ‘lovcountry’ b. ‘lovecountr’ c. ‘lovcountry m’ d. ‘i lovcountr’

Q119. >>> max(“my name is”) will display ____


a. a b. name c. y d. is

Q120. “max”[: : -1].startswith(“x”) will display _________


a. x b. m c. True d. False

Q121. In python “a” is an example of _______________________


a. String data type b. Character data type
c. Integer data type d. None of the above

Q122. Concatenation of string means _________________


a. Joining of strings b. Splitting of strings
c. Slicing of strings d. Repetition of strings

Q123. Read the statements given below and identify the right option
Statement A : >>>str1[6] gives sixth character of the string “str1”.
Statement B : string indices must be of type integers.
a. Statement A is correct.
b. Statement B is correct.
c. Statement A is correct, but Statement B is incorrect.
d. Statement A is incorrect, but Statement B is correct.
Q124. Read the statements given below and identify the right option
Statement A : Python allows an index value to be negative also.
Statement B : Negative indices are used when we want to access the characters of the string
from left to right.
a. Statement A is correct.
b. Statement B is correct.
c. Statement A is correct, but Statement B is incorrect.
d. Statement A is incorrect, but Statement B is correct.

Q125. Read the statements given below and identify the right option
Statement A : A string is an immutable data type.
Statement B : Contents of the string cannot be changed after it has been created.
a. Statement A is correct.
b. Statement B is correct.
c. Statement A is correct, and Statement B is also correct.
d. Statement A is incorrect, but Statement B is correct.

Q126. Read the statements given below and identify the right option
Statement A : Python has two membership operators ‘in’ and ‘not in’
Statement B : The ‘in’ operator takes two strings and returns False if the first string appears as a
substring in the second string, otherwise it returns True .
a. Statement A is correct.
b. Statement B is correct.
c. Statement A is correct, but Statement B is incorrect.
d. Statement A is incorrect, but Statement B is correct.

Q127. Read the statements given below and identify the right option
Statement A : count( ) function returns the first occurrence of index of substring str occurring in
the given string.
Statement B : lower( ) function converts the upper case letters to lower case .
a. Statement A is correct.
b. Statement B is correct.
c. Statement A is correct, but Statement B is incorrect.
d. Statement A is incorrect, but Statement B is correct.

You might also like