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




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




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




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




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




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




7. Which of the following expressions results in an error?




8. Which of the following represents the bitwise XOR operator?




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




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




11. The one’s complement of 110010101 is:




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




13. What will be the output of the following Python expression? 4^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.




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




16. Which of the following expressions can be used to multiply a given number ‘a’ by 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)




18. What is the two’s complement of -44?




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




42. What will be the output of the following Python code? s='%s, %s & %s' s%('mumbai', 'kolkata', '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')




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




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




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




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




48. What will be the output of the following Python code? l=list('HELLO') 'first={0[0]}, third={0[2]}'.format(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)




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