0% found this document useful (0 votes)
731 views12 pages

String MCQ ANS

The document contains 30 multiple choice questions about Python strings. It covers topics like string indexing, formatting, methods, operators and built-in functions related to strings. The questions test concepts like string traversal, concatenation, slicing, length calculation, escape sequences and more.

Uploaded by

lucifergamer996
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)
731 views12 pages

String MCQ ANS

The document contains 30 multiple choice questions about Python strings. It covers topics like string indexing, formatting, methods, operators and built-in functions related to strings. The questions test concepts like string traversal, concatenation, slicing, length calculation, escape sequences and more.

Uploaded by

lucifergamer996
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

Q1. Following is an example Q6.

Write the output of the following


of ___________________ code :
a= "Welcome to \
sv = “csiplearninghub.com” blog"
print(a)
a. List a. Welcome to blog
b. String
b.
c. Dictionary
d. None of the above
Welcome to \
Q2. Python considered the character blog
enclosed in triple quotes as String.(T/F) c.
a. True
b. False Welcome to
blog
d. Error
Q3. Write the output of the following.
a = "Blog"
a ='a' Q7. Write the output of the following
print(a) code :
a. Bloga str = "Welcome"
b. aBlog
str[2] = 'a'
c. Blog
d. a print(str)
a. Weacome
b. Error
Q4. Write the output of the following: c. aWelcome
a="We\nto my \nb\t ok" d. Welcomea
print(a)
a.
8. Write the output of the following
We code :
to my str = "Welcome"
b ok l=len(str)
b. print(l)
a. 6
We b. 7
to myb ok c. 8
c. d. Error
Q9. What we call the following:
Weto \n
my \t
b ok a. Escape Sequence
d. None of the above b. Special Character
c. Don’t have any common term
Q5. Write the output of the following d. Keyword
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
Q10. Write the output of the following Q15. String traversal can be done
code : using ‘for’ loop only.(T/F)
a = '''A a. True
B b. False
C'''
print(a)
a. ABC Q16. Which of the following statement
b. is correct in accessing each element of
string?
A a)
BC a="Learning"
c. while(i):
print(i)
A
B b)
C a="Learning"
d. Error for i in a:
print(i)
Q11. What is the index value of ‘i’ in a. a only
string “Learning” b. b only
a. 5 c. both a and b
b. 3 d. None of the above
c. 6
d. 7 Q17. Name the function which is used
to find length of string.
Q12. Index value in String should be a. length( )
of type ________________ b. len( )
a. Float c. strlen( )
b. Integer d. slen( )
c. String
d. Boolean
Q18. Write the output of the following
Q13. What type of error is returned by code :
the following : for i in "STR":
str = "Learning" print(i)
print(str[10]) a.
a. Error in Index
b. Index out of range in string S
c. IndexError TR
d. None of the above b.

Q14. Which character will have same STR


index value when you access elements c.
from the beginning and from the
end(ignore the negative sign) in the S T R
following string. d.
s = “Welcome to my blog”
a. ‘t’ S
b. ‘ ‘ T
c. ‘o’ R
d. ‘t’
Q19. Write the output of the following Q24. How many operators are used in
code : the following statement?
a="Learn" 7 + 4 * 8 // 2 ** 2 - 6 / 1
while(a): a. 5
print(a) b. 6
a. c. 7
d. 8
L
e Q25. Write the output of the following
a code :
r s="blog"
n for i in range(-1,-len(s),-1):
b. Error
print(s[i],end="$")
c. Infinite Loop
a. g$o$l$b$
d. Learn
b. g$o$l$
Q20. Which operator is used with
integers as well as with strings? c. Error
a. / d. None of the above
b. //
c. ** Q26. Write the output of the following
d. * code :
s= "str"
Q21. Write the output of the s1 = "string"
following: print(s1 in s)
2 + '3' a. True
a. 2 3 b. False
b. 23 c. Error
c. SyntaxError d. None of the above
d. TypeError Q27. Write the output of the following
code :
Q22. Which operator is used for string print("Amita" > "amit")
concatenation? a. True
a. * b. False
b. // c. Error
c. + d. None of the above
d. –
Q28. What is the ASCII value of “A”?
Q23. Write the output of the following a. 97
code : b. 66
for i in (1,2,3): c. 65
print("@" * i) d. 96
a. Error
b. @@@@@@ Q29. Write the output of the following
c. code :
print("Str"[1:2])
@ a. t
@@ b. No Output
@@@ c. Error
d. d. None of the above

@@@@@@
Q30. Write the output of the following Q35. Which of the following is not a
code : String built in functions?
for i in range(65,70): a. isupper( )
print(chr(i)) b. lower( )
a. Error c. partition( )
b. TypeError d. swapcases( )
c.
Q36. Write the output of the
A following:
B for i in range(91,100):
C if chr(i)=='a':
D pass
E else:
d. print(i)
a.
ABCDE
91
Q31. Write the output of the 92
following: 93
print(“A#B#C#D#E”.split(“#”,2)) 94
a. [‘A’, ‘B’, ‘C#D#E’] 95
b. [‘A#’, ‘B#’, ‘C#D#E’] 96
c. [‘A’, ‘B’, ‘C’ , ‘D’ , ‘E’] 97
d. Error 98
99
Q32. Write the output of the b.
following:
print(“A#B#C#D#E”.replace(“#”,”?”)) 91
a. A#B#C#D#E 92
b. A?B?C?D?E 93
c. Can not replace as Strings are 94
immutable 95
d. Error 96
98
Q33. Write the output of the 99
following: c.
print(“I love my Country”.find(“o”,4))
a. 3 91
b. 12 92
c. 11 93
d. 3,11 94
95
Q34. Write the output of the following.
96
print(‘#’.join(“12345”))
d. Error
a. #12345
Q37. Write the output of the
b. #12345# following:
c. 1#2#3#4#5 print(len("\\\\\\///"))
d. 1#2#3#4#5# a. 9
b. Error
c. 3
d. 6
Q41. Which of the following is a
Q38. Which of the following function mapping data type?
returns the ASCII/Unicode value a. String
character? b. List
a. asc( ) c. Tuple
b. ord( ) d. Dictionary
c. asci( )
d. ascii( ) Q42. A _____________ can be created
by enclosing one or more characters in
Q39. Which of the following single, double or triple quote.
statements will also return the same a. String
result as given statement? b. List
print(“Computer” + “Computer”) c. Tuple
a. print(“Computer” , ” “, “Computer”) d. Dictionary
b. print(“Computer”,”Computer”)
c. print(“Computer” **2) Q43. Characters in a string can
d. print(“Computer” * 2) be _________ enclosed in quotes.
a. Digits
Q40. Write the output of the b. white space
following: c. letter
for i in range(len("python"),12,2): d. All of the above
print("python"[i-6])
a. Q44. Each individual character in a
string can be accessed using a
p technique called ____________
t a. Indexing
o b. Replication
b. c. Concatenation
d. None of the above
p
y Q45. If we give index value out of the
t range then we get an ___
h a. ValueError
o b. SyntaxError
n c. IndexError
c. d. Error

y Q46. The index of the first character


h ____________ on the string is 0
n a. from left
d. b. from right
c. from middle
p d. none of the above
y Q47. What type of error is returned by
t statement :
h >>> str[1.5]
a. SyntaxError
b. ValueError
c. IndexError
d. TypeError
Q48. Write the output of the following.
str = “python” Q55. str[5 : 11] will return
print(str[2+1]) ___________ characters.
a. t a. 5
b. h b. 6
c. th c. 11
d. Error d. None of the above

Q49. Content of string can not be Q56. str[11 : 5] will return


changed, it means that string is ____________
a. mutable a. empty string
b. immutable b. complete string
c. reversible c. string of six characters
d. none of the above d. None of the above

Q50. What type of error is returned by Q57. str[ : ] will


following code: return _______________
>>> str1 = “Hello World!” a. empty string
>>> str1[1] = ‘a’ b. Complete String
a. TypeError c. Partial String
b. SyntaxError d. Error
c. ValueError
d. NoError Q58. Slice operation can also take a
third parameter that specifies
Q51. Python allows the ________
_____________ operations on string a. Starting index
data type. b. Ending index
a. Concatenation c. Step Size
b. Membership d. None of the above
c. Slicing
d. All of the above Q59. Which of the following is correct
slicing operation to extract every kth
Q52. Write the output of the following. character from the string str1 starting
>>> str1 = ‘Hello World!’ from n and ending at m-1.
>>> ‘W’ in str1 a. str1[: : k]
a. True b. str1[n : m+1 : k]
b. False c. str1[n : m : k ]
c. No d. str1[m : n : k ]

Q53. _____________ method is used to Q60. Which of the following will


access some part of a string or return reverse string str1?
substring. a. str1[ : : -1]
a. Slicer b. str1[: : 1]
b. Slicing c. str1[: -1 : -1 ]
c. Membership d. None of the above
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
Q61 We can access each character of a
string or traverse a string Q67. Write the output of the following.
using _______________ >>> str1 = ‘Hello World! Hello
a. for loop only >>> str1.index(‘Hee’)
b. while loop only a. 0
c. both of the above b. -1
d. conditional statement c. Error
d. None of the above
Q62. Which of the following function
returns the string with first letter of Q68. Write the output of the following.
every word in the string in uppercase >>> str1 = ‘Hello World!’
and rest in lowercase? >>> str1.endswith(‘World!’)
a. swapcase( ) a. True
b. upper( ) b. False
c. title( ) c. Yes
d. capitalize( ) d. Error

Q63. Write the output of the Q69. Write the output of the following.
following: s = “hello 123”
s = ” Hello” print(s.islower())
print(s.find(‘a’)) a. False
a. 0 b. True
b. -1 c. Error
c. 1 d. None of the above
d. Error
Q70. Write the output of the following
Q64. What index value is returned by :
the following code? >>> str1 = ‘HelloWorld!!’
s = “Hello” >>> str1.isalnum()
print(s.find(‘l’)) a. False
a. 2 b. True
b. 3 c. Error
c. 4 d. None of the above
d. -2
Q71. Write the output of the
Q65. Following code will return ? following:
s = “Hello” >>> str1 = 'hello WORLD!'
print(s.count(‘l’,2,5)) >>> str1.title()
a. 2 a. HELLO world
b. 3 b. Hello World
c. 1 c. Hello world
d. none of the above d. HeLlO WoRlD

Q66. Name a function which is same as Q72. Write the output of the following
find() but raises an exception if the :
substring is not present in the given >>> str1 = 'Hello World! Hello Hello'
string. >>> str1.count('Hello',12,25)
a. index( ) a. 1
b. endswith( ) b. 2
c. startswith( ) c. 3
d. count( ) d. 4
Q73. Write the output of the following Q79. >>> “Hey!”.endswith(‘!’) will
: return _____________________
>>> str1 = 'Hello World! Hello Hello' a. True
>>> str1.count('Hello') b. False
a. 1 c. Error
b. 2 d. None of the above
c. 3
d. 4 Q80. Which of the function returns
Boolean value?
Q74. Write the output of the following a. find( )
: b. index( )
print("Absbcbcgdbc".count("b",4)) c. endwith( )
a. 1 d. endswith( )
b. 2
c. 3 Q81. Write the output of the
d. 4 following:
>>> str1 = 'String MCQ'
Q75. Write the output of the following >>> str1.startswith('Str')
: a. True
print("Absbcbcgdbc".find("b",5)) b. False
a. 1 c. Yes
b. 2 d. No
c. 5
d. 6 Q82. Write the output of the
following:
Q76. Which of the following function print("Welcome-Python".isalnum())
returns the index value of first a. True
occurrence of substring occurring in b. False
the given string. c. Yes
a. index( ) d. No
b. find( )
c. Both of the above Q83. Write the output of the
d. None of the above following:
print(str("WelcomePython".isalnum()).u
Q77. find( ) function pper())
returns ___________ if the substring is a. TRUE
not present in the given string b. True
a. 0 c. FALSE
b. 1 d. Error
c. -1
d. Error Q84. Write the output of the
following:
Q78. index( ) function >>> str1 = 'hello ??'
returns _______________ if the >>> str1.islower( )
substring is not present in the given a. No
string b. True
a. 0 c. False
b. 1 d. Error
c. -1
d. Error
Q85. Which of the following function
returns True if the string is non-empty
and has all uppercase alphabets. Q91. split( ) function returns the
a. islower( ) _______________of words delimited
b. isupper( ) by the specified substring.
c. Islower( ) a. List
d. istitle b. Tuple
c. Dictionary
Q86. Write the output of the d. None of the above
following:
>>> str1 = 'Hello World!' Q92. If no delimiter is given in split( )
>>> str1.replace('o' , '*') function then words are separated
a. ‘Hello World!’ by ____________
b. ‘Hell* W*rld!’ a. space
c. ‘Hello W*rld!’ b. colon
d. Error c. semi colon
d. None of the above

Q87. Write the output of the Q93. Write the output of the
following: following:
>>> str1 = 'India is a Great is "python".join("@")
Country' a. ‘p@y@t@h@o@n’
>>> str1.partition('is') b. ‘p@y@t@h@o@n@’
a. (‘India ‘, ‘is’, ‘ a Great is Country’) c. ‘@p@y@t@h@o@n@’
b. (‘India ‘, ‘is’, ‘a Great’, ‘is’, d. ‘@’
‘Country’)
c. (‘India ‘, ‘is’, ‘ a Great Country’) Q94. Write the output of the
d. Error following:
"@".join("python")
Q88. Write the output of the a. ‘p@y@t@h@o@n’
following: b. ‘p@y@t@h@o@n@’
str = "Amit is a is a" c. ‘@p@y@t@h@o@n@’
s = str.partition('is') d. ‘@’
print(s[1])
a. is a
b. a Q95. Write the output of the
c. is following:
d. i >>> len(" python".lstrip()) #2 spaces
are given before "python"
Q89. partition( ) function of string in a. 5
python return the result in the form b. 6
of _________________ c. 7
a. String d. 8
b. List
c. Tuple Q96. Which of the following function
d. Dictionary removes only leading spaces from the
string?
Q90. partition() function divides the a. strip( )
main string into ________ substring. b. lstrip( )
a. 1 c. rstrip( )
b. 2 d. Lstrip( )
c. 3
d. 4
Q97. Which of the following function Q104. print(“aNd&*”.swapcase()) will
can take maximum three display ________________
arguments/parameters? a. AnD*&
a. find( ) b. AnD&*
b. index( ) c. aNd&*
c. count( ) d. Error
d. All of the above
Q105. Write the output of the
Q98. Which of the following function following:
return the integer value? print('hash-tag'.title())
a. lower( ) a. HashTag
b. upper( ) b. Hash-tag
c. islower( ) c. Hash-Tag
d. find( ) d. Error

Q99. Which of the following is not an Q106. Fill in the blank given below to
inbuilt function of string? get output – “amit is a g@@d boy”
a. length( ) print('amit is a good boy'.replace('o',
b. find( ) '@', _________ ))
c. endswith( ) a. 0
d. split( ) b. 1
c. 2
Q100. Which function in the following d. Nothing
statement will execute first?
print("amit".lower().upper()) Q107. print(‘Welcome TO My
a. print( ) Blog’.istitle()) will
b. lower( ) display ________________
c. upper( ) a. True
d. None of the above b. False
c. Error
d. None of the above
Q101. Which function in the following
statement will execute last? Q108. print(‘Welcome TO My
print("amit".lower().upper()) Blog'[2:6]) will display __________
a. print( ) a. lcom
b. lower( ) b. lcome
c. upper( ) c. lco
d. None of the above d. None of the above
Q109. print(‘Welcome TO My
Q102. Write the output of the Blog'[2:6] + ‘Welcome TO My
following: Blog'[5:9]) will display ___
print('aisabisacisadisae'.split('isa',3)) a. lcomme T
a. [‘a’, ‘b’, ‘c’, ‘disae’] b. lcomme
b. [‘a’, ‘b’, ‘cisadisae’] c. lcomme To
c. [‘a’, ‘b’, ‘c’, ‘d’, ‘e’] d. None of the above
d. None of the above
Q103. Write the output of the Q110. print(“WZ-1,New Ganga
following: Nagar,New Delhi”.rfind(‘New’)) will
print('aisabisacisadisae'.split('isa')) display _____
a. [‘a’, ‘b’, ‘c’, ‘disae’] a. 21
b. [‘a’, ‘b’, ‘cisadisae’] b. 5
c. [‘a’, ‘b’, ‘c’, ‘d’, ‘e’] c. 22
d. None of the above d. 4
Q111. Which of the following STRTrue
statement will return error? STRTrue
a. print(“Hello” + “Bye”) STRTrue
b. print(“Hello” + “123”)
c. print(“Hello” + 123) d. Error
d. print(“456” + “123”)
Q115. Select the wrong option in
Q112. print(ord(“A”)) will return ___ reference to the statement given
a. integer value below:
b. string value (operand1) * (operand2) = No error
c. list a. Both operands can be of type
d. tuple integer
b. operand1 can be of type integer and
Q113. Write the output of the operand2 can be of type string
following: c. operand1 can be of type string and
s="str" operand2 can be of type integer
for i in s: d. Both operands can be of type string
if i.islower():
print(s.swapcase() Q116. print(“a” in “amit”) will
a. return _________________
a. Integer value
S b. String value
T c. Boolean value
R d. None of the above

b. STR Q117. >>>chr(97) will


return ________________
c. a. A
b. a
STR c. B
STR d. b
STR

d. None of the above Q118. Write the output of the


following:
>>> s = "i love my country"
Q114. Write the output of the >>> r = "i love my class"
following: >>> s[2:5] + s[-7:]
s="str" a. ‘lovcountry’
for i in range(len(s)): b. ‘lovecountr’
s=s.upper() c. ‘lovcountry m’
print(s.upper() + str(s.islower())) d. ‘i lovcountr’
a.
Q119. >>> max(“my name is”) will
STRFalse display ____
STRFalse a. a
STRFalse b. name
b. c. y
d. is
STRFalse
STRFalse
c.
Q120. “max”[: : -1].startswith(“x”) Q125. Read the statements given
will display _________ below and identify the right option
a. x Statement A : A string is an
b. m immutable data type.
c. True Statement B : Contents of the string
d. False cannot be changed after it has been
created.
Q121. In python “a” is an example of
_______________________ a. Statement A is correct.
a. String data type b. Statement B is correct.
b. Character data type c. Statement A is correct, and
c. Integer data type Statement B is also correct.
d. None of the above d. Statement A is incorrect, but
Statement B is correct.
Q122. Concatenation of string means
_________________ Q126. Read the statements given
a. Joining of strings below and identify the right option
b. Splitting of strings Statement A : Python has two
c. Slicing of strings membership operators ‘in’ and ‘not
d. Repetition of strings in’
Statement B : The ‘in’ operator takes
Q123. Read the statements given two strings and returns False if the
below and identify the right option first string appears as a substring in
Statement A : >>>str1[6] gives sixth the second string, otherwise it
character of the string “str1”. returns True .
Statement B : string indices must be of
type integers. a. Statement A is correct.
b. Statement B is correct.
a. Statement A is correct. c. Statement A is correct, but
b. Statement B is correct. Statement B is incorrect.
c. Statement A is correct, but d. Statement A is incorrect, but
Statement B is incorrect. Statement B is correct.
d. Statement A is incorrect, but
Statement B is correct. Q127. Read the statements given
below and identify the right option
Q124. Read the statements given Statement A : count( ) function
below and identify the right option returns the first occurrence of index of
Statement A : Python allows an index substring str occurring in the given
value to be negative also. string.
Statement B : Negative indices are Statement B : lower( ) function
used when we want to access the converts the upper case letters to
characters of the string from left lower case .
to right.
a. Statement A is correct. a. Statement A is correct.
b. Statement B is correct. b. Statement B is correct.
c. Statement A is correct, but c. Statement A is correct, but
Statement B is incorrect. Statement B is incorrect.
d. Statement A is incorrect, but d. Statement A is incorrect, but
Statement B is correct. Statement B is correct.

You might also like