Home
MCQS
Python MCQ Quiz Hub
MCQ on Python String Set 1
Choose a topic to test your knowledge and improve your Python skills
1. Following is an example of ___________________ sv = “csiplearninghub.com”
List
String
Dictionary
None of the above
2. Write the output of the following. a = "Blog" a ='a' print(a)
Bloga
aBlog
Blog
a
3. Write the output of the following: a="We to my b ok" print(a)
We to my b ok
We to myb ok
Weto my b ok
None of the above
4. Write the output of the following code : a= "Welcome to "my" blog" print(a)
Welcome to “my” blog
Welcome to ”my” blog
Error
None of the above
5. Write the output of the following code : a= "Welcome to blog" print(a)
Welcome to blog
Welcome to blog
Welcome to blog
Error
6. Write the output of the following code : str = "Welcome" str[2] = 'a' print(str)
Weacome
Error
aWelcome
Welcomea
7. Write the output of the following code : str = "Welcome" l=len(str) print(l)
6
7
8
Error
8. What we call the following:
Escape Sequence
Special Character
Don’t have any common term
Keyword
9. Write the output of the following code : a = '''A B C''' print(a)
ABC
A BC
A B C
Error
10. What is the index value of ‘i’ in string “Learning”
5
3
6
7
11. Index value in String should be of type ________________
Float
Integer
String
Boolean
12. What type of error is returned by the following : str = "Learning" print(str[10])
Error in Index
Index out of range in string
IndexError
None of the above
13. 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”
‘t’
‘ ‘
‘o’
‘t’
14. 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 only
b only
both a and b
None of the above
15. Name the function which is used to find length of string.
length( )
len( )
strlen( )
slen( )
16. Write the output of the following code : for i in "STR": print(i)
S TR
STR
S T R
S T R
17. Write the output of the following code : a="Learn" while(a): print(a)
L e a r n
Error
Infinite Loop
Learn
18. Which operator is used with integers as well as with strings?
/
//
**
*
19. Write the output of the following: 2 + '3'
2 3
23
SyntaxError
TypeError
20. Which operator is used for string concatenation?
*
//
+
-
21. Write the output of the following code : for i in (1,2,3): print("@" * i)
Error
@@@@@@
@ @@ @@@
@ @ @ @ @ @
22. How many operators are used in the following statement? 7 + 4 * 8 // 2 ** 2 - 6 / 1
5
6
7
8
23. Write the output of the following code : s="blog" for i in range(-1,-len(s),-1): print(s[i],end="$")
g$o$l$b$
g$o$l$
Error
None of the above
24. Write the output of the following code : s= "str" s1 = "string" print(s1 in s)
True
False
Error
None of the above
25. Write the output of the following code : s= "str" Write the output of the following code : for i in range(65,70): print(chr(i))
Error
TypeError
A B C D E
ABCDE
26. Write the output of the following code : s= "str" Write the output of the following code : for i in range(65,70): print(chr(i))
Error
TypeError
A B C D E
ABCDE
27. Write the output of the following: print(“A#B#C#D#E”.split(“#”,2))
[‘A’, ‘B’, ‘C#D#E’]
[‘A#’, ‘B#’, ‘C#D#E’]
[‘A’, ‘B’, ‘C’ , ‘D’ , ‘E’]
Error
28. Write the output of the following: print(“A#B#C#D#E”.replace(“#”,”?”))
A#B#C#D#E
A?B?C?D?E
Can not replace as Strings are immutable
Error
29. Write the output of the following: print(“I love my Country”.find(“o”,4))
3
12
11
3,11
30. Write the output of the following. print(‘#’.join(“12345”))
#12345
#12345#
1#2#3#4#5
1#2#3#4#5#
31. Which of the following is not a String built in functions?
partition( )
isupper( )
lower( )
swapcases( )
32. Write the output of the following: print(len("\\\///"))
9
Error
3
6
33. Which of the following function returns the ASCII/Unicode value character?
asc( )
ord( )
asci( )
ascii( )
34. Which of the following statements will also return the same result as given statement? print(“Computer” + “Computer”)
print(“Computer” , ” “, “Computer”)
print(“Computer”,”Computer”)
print(“Computer” **2)
print(“Computer” * 2)
35. Write the output of the following: for i in range(len("python"),12,2): print("python"[i-6])
p t o
p y t h o n
y h n
p y t h
36. Which of the following is a mapping data type?
String
List
Tuple
Dictionary
37. A _____________ can be created by enclosing one or more characters in single, double or triple quote
String
List
Tuple
Dictionary
38. Characters in a string can be _________ enclosed in quotes.
Digits
white space
letter
All the above
39. Each individual character in a string can be accessed using a technique called _____
Indexing
Replication
Concatenation
None of the above
40. If we give index value out of the range then we get an ___
ValueError
SyntaxError
IndexError
Error
41. The index of the first character ____________ on the string is 0
from left
from right
from middle
None of the above
42. What type of error is returned by statement : >>> str[1.5]
SyntaxError
ValueError
. IndexErro
. TypeError
43. Write the output of the following. str = “python” print(str[2+1])
t
h
th
Error
44. Content of string can not be changed, it means that string is
mutable
immutable
reversible
None of the above
45. Python allows _____________ operations on string data type.
Concatenation
Membership
Slicing
Slicing
46. _________ method is used to access some part of a string or substring.>>> str1 = ‘Hello World!’ >>> ‘W’ in str1
Slicer
Slicing
Membership
None of the above
47. str[5 : 11] will return ___________ character
5
6
11
None of the above
48. str[11 : 5] will return _________
empty string
complete string
string of six characters
None of the above
49. Slice operation can also take a third parameter that specifies the _____
Starting index
Ending index
Step Size
None of the above
50. 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.
str1[: : k]
str1[n : m+1 : k]
str1[n : m : k ]
str1[m : n : k ]
51. Which of the following will return reverse string str1?
str1[ : : -1]
str1[: : 1]
str1[: -1 : -1 ]
None of the above
52. We can access each character of a string or traverse a string using ___
for loop only
while loop only
both of the above
conditional statement
53. Which of the following function returns the string with first letter of every word in the string in uppercase and rest in lowercase?
swapcase( )
upper( )
title( )
capitalize( )
54. Write the output of the following: s = ” Hello” print(s.find(‘a’))
0
-1
1
Error
55. What index value is returned by the following code? s = “Hello” print(s.find(‘l’))
2
3
4
-2
56. Following code will return ? s = “Hello” print(s.count(‘l’,2,5))
2
3
1
None of the above
57. Name a function which is same as find() but raises an exception if the substring is not present in the given string.
index( )
endswith( )
startswith( )
count( )
58. Write the output of the following. >>> str1 = ‘Hello World! Hello >>> str1.index(‘Hee’)
0
1
Error
None of the above
59. Write the output of the following. >>> str1 = ‘Hello World!’ >>> str1.endswith(‘World!’)
True
False
yes
Error
60. Write the output of the following. s = “hello 123” print(s.islower())
False
True
Error
None of the above
61. Write the output of the following: >>> str1 = 'hello WORLD!' >>> str1.title()
HELLO world
Hello World
Hello world
HeLlO WoRlD
62. Write the output of the following : >>> str1 = ‘HelloWorld!!’ >>> str1.isalnum()
False
True
Error
None of the above
63. Write the output of the following : >>> str1 = 'Hello World! Hello Hello' >>> str1.count('Hello',12,25)
1
2
3
4
64. Write the output of the following : >>> str1 = 'Hello World! Hello Hello' >>> str1.count('Hello')
1
2
3
4
65. Write the output of the following : print("Absbcbcgdbc".count("b",4))
1
2
3
4
66. Write the output of the following : print("Absbcbcgdbc".find("b",5))
1
2
5
6
67. Which of the following function returns the index value of first occurrence of substring occurring in the given string.
index( )
. find( )
Both of the above
None of the above
68. find( ) function returns ___________ if the substring is not present in the given string
0
1
-1
Error
69. index( ) function returns _______________ if the substring is not present in the given string
0
1
-1
Error
70. >>> “Hey!”.endswith(‘!’) will return ______
True
False
Error
None of the above
71. Which of the function returns Boolean value?
find( )
index( )
endwith( )
endswith( )
72. Write the output of the following: >>> str1 = 'String MCQ' >>> str1.startswith('Str')
True
False
yes
No
73. Write the output of the following: print("Welcome-Python".isalnum())
True
False
yes
No
74. Write the output of the following: print(str("WelcomePython".isalnum()).upper())
TRUE
True
FLAS
Error
75. Write the output of the following: >>> str1 = 'hello ??' >>> str1.islower( )
NO
True
false
Error
76. Which of the following function returns True if the string is non-empty and has all uppercase alphabets.
islower( )
islower( )
Islower( )
islower( )
77. Write the output of the following: >>> str1 = 'Hello World!' >>> str1.replace('o' , '*')
Hello World!’
‘Hell* W*rld!’
‘Hello W*rld!’
Error
78. Write the output of the following: >>> str1 = 'India is a Great is Country' >>> str1.partition('is')
(‘India ‘, ‘is’, ‘ a Great is Country’)
(‘India ‘, ‘is’, ‘a Great’, ‘is’, ‘Country’)
(‘India ‘, ‘is’, ‘ a Great Country’)
Error
79. Write the output of the following: str = "Amit is a is a" s = str.partition('is') print(s[1])
is a
a
is
i
80. partition( ) function of string in python return the result in the form of ____
String
List
Tuple
Dictionary
81. partition() function divides the main string into ________ substring.
1
2
3
4
82. split( ) function returns the _______________of words delimited by the specified substring.
List
Tuple
Dictionary
None of the above
83. If no delimiter is given in split( ) function then words are separated by ____
space
colon
semi colon
None of the above
84. Write the output of the following: "python".join("@")
‘p@y@t@h@o@n’
p@y@t@h@o@n@’
‘@p@y@t@h@o@n@’
@’
85. Write the output of the following: "@".join("python")
p@y@t@h@o@n’
‘p@y@t@h@o@n@’
@p@y@t@h@o@n@’
‘@
86. Write the output of the following: >>> len(" python".lstrip()) #2 spaces are given before "python"
5
6
7
8
87. Which of the following function removes only leading spaces from the string?
strip( )
lstrip( )
rstrip( )
Lstrip( )
88. Which of the following function can take maximum three arguments/parameters?
find( )
index( )
count( )
All the above
89. Which of the following function return the integer value?
lower( )
upper( )
islower( )
find( )
90. Which of the following is not an inbuilt function of string?
length( )
find( )
endswith( )
split( )
91. Which function in the following statement will execute first? print("amit".lower().upper())
print( )
lower( )
upper( )
None of the above
92. Which function in the following statement will execute last? print("amit".lower().upper())
print( )
lower( )
upper( )
None of the above
93. Write the output of the following: print('aisabisacisadisae'.split('isa',3))
[‘a’, ‘b’, ‘c’, ‘disae’]
[‘a’, ‘b’, ‘cisadisae’]
[‘a’, ‘b’, ‘c’, ‘d’, ‘e’]
None of the above
94. Write the output of the following: print('aisabisacisadisae'.split('isa'))
[‘a’, ‘b’, ‘c’, ‘disae’]
[‘a’, ‘b’, ‘cisadisae’]
[‘a’, ‘b’, ‘c’, ‘d’, ‘e’]
None of the above
95. print(“aNd&*”.swapcase()) will display _
AnD*&
AnD&*
aNd&*
Error
Submit