Home
MCQS
Python MCQ Quiz Hub
Python Mcq Set 2
Choose a topic to test your knowledge and improve your Python skills
1. What will be the output of the following Python code snippet if x=1? x<<2
8
1
2
4
2. What will be the output of the following Python expression? bin(29)
‘0b10111’
‘0b11101’
‘0b11111’
‘0b11011’
3. What will be the value of x in the following Python expression, if the result of that expression is 2? x>>2
8
4
2
1
4. What will be the output of the following Python expression? int(1011)?
1011
11
13
1101
5. To find the decimal value of 1111, that is 15, we can use the function:
int(1111,10)
int(‘1111’,10)
int(1111,2)
int(‘1111’,2)
6. What will be the output of the following Python expression if x=15 and y=12? x & y
b1101
0b1101
12
1101
7. Which of the following expressions results in an error?
int(1011)
int(‘1011’,23)
int(1011,2)
int(‘1011’)
8. Which of the following represents the bitwise XOR operator?
&amp;
^
|
!
9. What is the value of the following Python expression? bin(0x8)
‘0bx1000’
8
1000
‘0b1000’
10. What will be the output of the following Python expression? 0x35 | 0x75
115
116
117
118
11. The one’s complement of 110010101 is:
001101010
110010101
001101011
110010100
12. Bitwise _________ gives 1 if either of the bits is 1 and 0 when both of the bits are 1.
OR
AND
XOR
NOT
13. What will be the output of the following Python expression? 4^12
2
4
8
12
14. Any odd number on being AND-ed with ________ always gives 1. Hint: Any even number on being AND-ed with this value always gives 0.
10
2
1
0
15. What will be the value of the following Python expression? bin(10-2)+bin(12^4)
0b10000
0b10001000
0b1000b1000
0b10000b1000
16. Which of the following expressions can be used to multiply a given number ‘a’ by 4?
a&lt;&lt;2
a&lt;&lt;4
a&gt;&gt;2
a&gt;&gt;4
17. What will be the output of the following Python code if a=10 and b =20? a=10 b=20 a=a^b b=a^b a=a^b print(a,b)
10 20
10 10
20 10
20 20
18. What is the two’s complement of -44?
1011011
11010100
11101011
10110011
19. What will be the output of the following Python expression? ~100?
101
-101
100
-100
20. What will be the output of the following Python code snippet? ['hello', 'morning'][bool('')]
error
no output
hello
morning
21. What will be the output of the following Python code? ['f', 't'][bool('spam')]
t
f
No output
error control
22. What will be the output of the following Python code? l=[1, 0, 2, 0, 'hello', '', []] list(filter(bool, l))
Error
[1, 0, 2, 0, ‘hello’, ”, []]
[1, 0, 2, ‘hello’, ”, []]
[1, 2, ‘hello’]
23. Which of the following Boolean expressions is not logically equivalent to the other three?
not(-6&lt;0 or-6&gt;10)
-6&gt;=0 and -6&lt;=10
not(-6&lt;10 or-6==10)
not(-6&gt;10 or-6==10)
24. What will be the output of the following Python code snippet? not(10<20) and not(10>30)
True
False
Error
No output
25. What will be the output of the following Python code snippet? X=”hi” print(“05d”%X)
00000hi
000hi
hi000
error
26. What will be the output of the following Python code snippet? X=”san-foundry” print(“%56s”,X)
56 blank spaces before san-foundry
56 blank spaces before san and foundry
56 blank spaces after san-foundry
no change
27. What will be the output of the following Python expression if x=456? print("%-06d"%x)
000456
456000
456
error
28. What will be the output of the following Python expression if X=345? print(“%06d”%X)
345000
000345
000000345
345000000
29. Which of the following formatting options can be used in order to add ‘n’ blank spaces after a given string ‘S’?
print(“-ns”%S)
print(“-ns”%S)
print(“%ns”%S)
print(“%-ns”%S)
30. What will be the output of the following Python expression if X = -122? print("-%06d"%x)
-000122
000122
–00122
-00122
31. What will be the output of the following Python expression if the value of x is 34? print(“%f”%x)
34.00
34.0000
34.000000
34.00000000
32. What will be the output of the following Python expression if x=56.236? print("%.2f"%x)
56.00
56.24
56.23
0056.236
33. What will be the output of the following Python expression if x=22.19? print("%5.2f"%x)
22.1900
22.00000
22.19
22.20
34. The expression shown below results in an error. print("-%5d0",989)
Error
1 hello you 4.0
1 hello 4 you
1 4 hello you
35. The output of which of the codes shown below will be: “There are 4 blue birds.”?
‘There are %g %d birds.’ %4 %blue
‘There are %d %s birds.’ %(4, blue)
There are %s %d birds.’ %[4, blue]
‘There are %d %s birds.’ 4, blue
36. What will be the output of the following Python code snippet? x=3.3456789 '%f | %e | %g' %(x, x, x)
Error
‘3.3456789 | 3.3456789+00 | 3.345678’
‘3.345678 | 3.345678e+0 | 3.345678’
‘3.345679 | 3.345679e+00 | 3.34568’
37. What will be the output of the following Python code snippet? x=3.3456789 '%-6.2f | %05.2f | %+06.1f' %(x, x, x)
‘3.35 | 03.35 | +003.3’
‘3.3456789 | 03.3456789 | +03.3456789’
Error
‘3.34 | 03.34 | 03.34+’
38. What will be the output of the following Python code snippet? x=3.3456789 '%s' %x, str(x)
Error
(‘3.3456789’, ‘3.3456789’)
(3.3456789, 3.3456789)
(‘3.3456789’, 3.3456789)
39. What will be the output of the following Python code snippet? '%(qty)d more %(food)s' %{'qty':1, 'food': 'spam'}
Error
No output
‘1 more foods’
‘1 more spam’
40. What will be the output of the following Python code snippet? a='hello' q=10 vars()
{‘a’ : ‘hello’, ‘q’ : 10, ……..plus built-in names set by Python….}
{……Built in names set by Python……}
{‘a’ : ‘hello’, ‘q’ : 10}
Error
41. What will be the output of the following Python code? s='{0}, {1}, and {2}' s.format('hello', 'good', 'morning')
‘hello good and morning’
‘hello, good, morning’
‘hello, good, and morning’
error
42. What will be the output of the following Python code? s='%s, %s & %s' s%('mumbai', 'kolkata', 'delhi')
mumbai kolkata &amp; delhi
Error
No output
‘mumbai, kolkata &amp; delhi’
43. What will be the output of the following Python code? t = '%(a)s, %(b)s, %(c)s' t % dict(a='hello', b='world', c='universe')
‘hello, world, universe’
‘hellos, worlds, universes’
Error
hellos, world, universe
44. What will be the output of the following Python code? '{a}, {0}, {abc}'.format(10, a=2.5, abc=[1, 2])
Error
‘2.5, 10, [1, 2]’
2.5, 10, 1, 2
’10, 2.5, [1, 2]’
45. What will be the output of the following Python code? '{0:.2f}'.format(1.234)
‘1’
‘1.234’
‘1.23’
‘1.2’
46. What will be the output of the following Python code? '{0:.2f}'.format(1.234)
‘1’
‘1.234’
‘1.23’
‘1.2’
47. What will be the output of the following Python code? '%x %d' %(255, 255)
‘ff, 255’
‘255, 255’
‘15f, 15f’
error control
48. What will be the output of the following Python code? l=list('HELLO') 'first={0[0]}, third={0[2]}'.format(l)
‘first=H, third=L’
‘first=0, third=2’
Error
‘first=0, third=L’
49. What will be the output of the following Python code? l=list('HELLO') p=l[0], l[-1], l[1:3] 'a={0}, b={1}, c={2}'.format(*p)
Error
“a=’H’, b=’O’, c=(E, L)”
“a=H, b=O, c=[‘E’, ‘L’]”
Junk value
50. The formatting method {1:<10} represents the ___________ positional argument, _________ justified in a 10 character wide field.
first, right
second, left
first, left
second, right
Submit