Home
MCQS
Python MCQ Quiz Hub
Python Mcq Set 5
Choose a topic to test your knowledge and improve your Python skills
1. What will be the output of the following Python code? x = (i for i in range(3)) for i in x: print(i)
0 1 2
error
0 1 2 0 1 2
none of the mentioned
2. What will be the output of the following Python code? x = (i for i in range(3)) for i in x: print(i) for i in x: print(i)
0 1 2
error
0 1 2 0 1 2
none of the mentioned
3. What will be the output of the following Python code? string = "my name is x" for i in string: print (i, end=", ")
m, y, , n, a, m, e, , i, s, , x,
m, y, , n, a, m, e, , i, s, , x
my, name, is, x,
error
4. What will be the output of the following Python code? string = "my name is x" for i in string.split(): print (i, end=", ")
m, y, , n, a, m, e, , i, s, , x
m, y, , n, a, m, e, , i, s, , x
my, name, is, x,
error
5. What will be the output of the following Python code snippet? a = [0, 1, 2, 3] for a[-1] in a: print(a[-1])
0 1 2 3
0 1 2 2
3 3 3 3
error
6. What will be the output of the following Python code snippet? a = [0, 1, 2, 3] for a[0] in a: print(a[0])
0 1 2 3
0 1 2 2
3 3 3 3
error
7. What will be the output of the following Python code snippet? a = [0, 1, 2, 3] i = -2 for i not in a: print(i) i += 1
-2 -1
0
error
none of the mentioned
8. What will be the output of the following Python code snippet? string = "my name is x" for i in ' '.join(string.split()): print (i, end=", ")
m, y, , n, a, m, e, , i, s, , x,
m, y, , n, a, m, e, , i, s, , x
my, name, is, x,
error
9. What will be the output of the following Python code? for i in range(10): if i == 5: break else: print(i) else: print("Here")
0 1 2 3 4 Here
0 1 2 3 4 5 Here
0 1 2 3 4
1 2 3 4 5
10. What will be the output of the following Python statement? >>>"a"+"bc"
a
bc
bca
abc
11. What will be the output of the following Python statement? >>>"abcd"[2:]
a
ab
cd
dc
12. The output of executing string.ascii_letters can also be achieved by:
string.ascii_lowercase_string.digits
string.ascii_lowercase+string.ascii_uppercase
string.letters
string.lowercase_string.uppercase
13. What will be the output of the following Python code? >>> str1 = 'hello' >>> str2 = ',' >>> str3 = 'world' >>> str1[-1:]
olleh
hello
h
o
14. What arithmetic operators cannot be used with strings?
+
*
–
all of the mentioned
15. What will be the output of the following Python code? >>>print (r" hello")
a new line and hello
hello
the letter r and then hello
error
16. What will be the output of the following Python statement? >>>print('new' 'line')
Error
Output equivalent to print ‘new line’
newline
new line
17. What will be the output of the following Python code? >>>str1="helloworld" >>>str1[::-1]
dlrowolleh
hello
world
helloworld
18. What will be the output of the following Python code? print(0xA + 0xB + 0xC)
0xA0xB0xC
Error
0x22
33
19. What will be the output of the following Python code? >>>example = "snow world" >>>print("%s" % example[4:7])
wo
world
sn
rl
20. What will be the output of the following Python code? >>>example = "snow world" >>>example[3] = 's' >>>print example
snow
snow world
Error
snos world
21. What will be the output of the following Python code? >>>max("what are you")
error
u
t
Y
22. Given a string example=”hello” what is the output of example.count(‘l’)?
2
1
None
0
23. What will be the output of the following Python code? >>>example = "helle" >>>example.find("e")
Error
-1
1
0
24. What will be the output of the following Python code? >>>example = "helle" >>>example.rfind("e")
-1
4
3
1
25. What will be the output of the following Python code? >>>example="helloworld" >>>example[::-1].startswith("d")
dlrowolleh
True
-1
None
26. To concatenate two strings to a third what statements are applicable?
s3 = s1 . s2
s3 = s1.add(s2)
s3 = s1.__add__(s2)
s3 = s1 * s2
27. What will be the output of the following Python statement? >>>chr(ord('A'))
A
B
a
error
28. What will be the output of the following Python statement? >>>print(chr(ord('b')+1))
a
b
c
A
29. Which of the following statement prints helloexample est.txt?
print(“helloexample est.txt”)
print(“hello\example\test.txt”)
print(“hello”example”test.txt”)
print(“hello”example” est.txt”)
30. Suppose s is “ World ”, what is s.strip()?
World
World
WORLD
World
31. The format function, when applied on a string returns ______
Error
int
bool
str
32. What will be the output of the “hello” +1+2+3?
hello123
hello
Error
hello6
33. What will be the output of the following Python code? >>>print("D", end = ' ') >>>print("C", end = ' ') >>>print("B", end = ' ') >>>print("A", end = ' ')
DCBA
A, B, C, D
D C B A
D, C, B, A will be displayed on four lines
34. What will be the output of the following Python statement?(python 3.xx) >>>print(format("Welcome", "10s"), end = '#') >>>print(format(111, "4d"), end = '#') >>>print(format(924.656, "3.2f"))
Welcome# 111#924.66
Welcome#111#924.66
Welcome#111#.66
Welcome # 111#924.66
35. What will be displayed by print(ord(‘b’) – ord(‘a’))?
0
1
-1
2
36. Say s=”hello” what will be the return value of type(s)?
int
bool
str
String
37. What is “Hello”.replace(“l”, “e”)?
Heeeo
Heelo
Heleo
None
38. To retrieve the character at index 3 from string s=”Hello” what command do we execute (multiple answers allowed)?
s[]
s.getitem(3)
s.__getitem__(3)
s.getItem(3)
39. To return the length of string s what command do we execute?
s.__len__()
len(s)
size(s)
s.size()
40. If a class defines the __str__(self) method, for an object obj for the class, you can use which command to invoke the __str__ method.
obj.__str__()
str(obj)
print obj
all of the mentioned
41. To check whether string s1 contains another string s2, use ____
s1.__contains__(s2)
s2 in s1
s1.contains(s2)
si.in(s2)
42. Suppose i is 5 and j is 4, i + j is same as ________
i.__add(j)
i.__add__(j)
i.__Add(j)
i.__ADD(j)
43. What function do you use to read a string?
input(“Enter a string”)
eval(input(“Enter a string”))
enter(“Enter a string”)
eval(enter(“Enter a string”))
44. Suppose x is 345.3546, what is format(x, “10.3f”) (_ indicates space).
__345.355
___345.355
___345.355
_____345.354
45. What will be the output of the following Python code? print("abc DEF".capitalize())
abc def
ABC DEF
Abc def
Abc Def
46. What will be the output of the following Python code? print("abc. DEF".capitalize())
abc. def
ABC. DEF
Abc. def
Abc. Def
47. What will be the output of the following Python code? print("abcdef".center())
cd
abcdef
error
none of the mentioned
48. What will be the output of the following Python code? print("abcdef".center(0))
cd
abcdef
error
none of the mentioned
49. What will be the output of the following Python code? print('*', "abcdef".center(7), '*')
* abcdef *
* abcdef *
*abcdef *
* abcdef*
50. What will be the output of the following Python code? print('*', "abcdef".center(7), '*', sep='')
* abcdef *
* abcdef *
*abcdef *
* abcdef*
Submit