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