Python MCQ Quiz Hub

Python Mcq Set 2

Choose a topic to test your knowledge and improve your Python skills

What will be the output of the following Python code snippet if x=1? x<<2





✅ Correct Answer: 4

What will be the output of the following Python expression? bin(29)





✅ Correct Answer: 2

What will be the value of x in the following Python expression, if the result of that expression is 2? x>>2





✅ Correct Answer: 1

What will be the output of the following Python expression? int(1011)?





✅ Correct Answer: 1

To find the decimal value of 1111, that is 15, we can use the function:





✅ Correct Answer: 4

What will be the output of the following Python expression if x=15 and y=12? x & y





✅ Correct Answer: 3

Which of the following expressions results in an error?





✅ Correct Answer: 3

Which of the following represents the bitwise XOR operator?





✅ Correct Answer: 2

What is the value of the following Python expression? bin(0x8)





✅ Correct Answer: 4

What will be the output of the following Python expression? 0x35 | 0x75





✅ Correct Answer: 3

The one’s complement of 110010101 is:





✅ Correct Answer: 1

Bitwise _________ gives 1 if either of the bits is 1 and 0 when both of the bits are 1.





✅ Correct Answer: 3

What will be the output of the following Python expression? 4^12





✅ Correct Answer: 3

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.





✅ Correct Answer: 3

What will be the value of the following Python expression? bin(10-2)+bin(12^4)





✅ Correct Answer: 4

Which of the following expressions can be used to multiply a given number ‘a’ by 4?





✅ Correct Answer: 1

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)





✅ Correct Answer: 3

What is the two’s complement of -44?





✅ Correct Answer: 2

What will be the output of the following Python expression? ~100?





✅ Correct Answer: 2

What will be the output of the following Python code snippet? ['hello', 'morning'][bool('')]





✅ Correct Answer: 3

What will be the output of the following Python code? ['f', 't'][bool('spam')]





✅ Correct Answer: 1

What will be the output of the following Python code? l=[1, 0, 2, 0, 'hello', '', []] list(filter(bool, l))





✅ Correct Answer: 4

Which of the following Boolean expressions is not logically equivalent to the other three?





✅ Correct Answer: 4

What will be the output of the following Python code snippet? not(10<20) and not(10>30)





✅ Correct Answer: 2

What will be the output of the following Python code snippet? X=”hi” print(“05d”%X)





✅ Correct Answer: 4

What will be the output of the following Python code snippet? X=”san-foundry” print(“%56s”,X)





✅ Correct Answer: 1

What will be the output of the following Python expression if x=456? print("%-06d"%x)





✅ Correct Answer: 3

What will be the output of the following Python expression if X=345? print(“%06d”%X)





✅ Correct Answer: 2

Which of the following formatting options can be used in order to add ‘n’ blank spaces after a given string ‘S’?





✅ Correct Answer: 4

What will be the output of the following Python expression if X = -122? print("-%06d"%x)





✅ Correct Answer: 3

What will be the output of the following Python expression if the value of x is 34? print(“%f”%x)





✅ Correct Answer: 3

What will be the output of the following Python expression if x=56.236? print("%.2f"%x)





✅ Correct Answer: 2

What will be the output of the following Python expression if x=22.19? print("%5.2f"%x)





✅ Correct Answer: 3

The expression shown below results in an error. print("-%5d0",989)





✅ Correct Answer: 3

The output of which of the codes shown below will be: “There are 4 blue birds.”?





✅ Correct Answer: 2

What will be the output of the following Python code snippet? x=3.3456789 '%f | %e | %g' %(x, x, x)





✅ Correct Answer: 4

What will be the output of the following Python code snippet? x=3.3456789 '%-6.2f | %05.2f | %+06.1f' %(x, x, x)





✅ Correct Answer: 1

What will be the output of the following Python code snippet? x=3.3456789 '%s' %x, str(x)





✅ Correct Answer: 2

What will be the output of the following Python code snippet? '%(qty)d more %(food)s' %{'qty':1, 'food': 'spam'}





✅ Correct Answer: 4

What will be the output of the following Python code snippet? a='hello' q=10 vars()





✅ Correct Answer: 1

What will be the output of the following Python code? s='{0}, {1}, and {2}' s.format('hello', 'good', 'morning')





✅ Correct Answer: 3

What will be the output of the following Python code? s='%s, %s & %s' s%('mumbai', 'kolkata', 'delhi')





✅ Correct Answer: 4

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')





✅ Correct Answer: 1

What will be the output of the following Python code? '{a}, {0}, {abc}'.format(10, a=2.5, abc=[1, 2])





✅ Correct Answer: 2

What will be the output of the following Python code? '{0:.2f}'.format(1.234)





✅ Correct Answer: 3

What will be the output of the following Python code? '{0:.2f}'.format(1.234)





✅ Correct Answer: 3

What will be the output of the following Python code? '%x %d' %(255, 255)





✅ Correct Answer: 1

What will be the output of the following Python code? l=list('HELLO') 'first={0[0]}, third={0[2]}'.format(l)





✅ Correct Answer: 1

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)





✅ Correct Answer: 3

The formatting method {1:<10} represents the ___________ positional argument, _________ justified in a 10 character wide field.





✅ Correct Answer: 2