Python MCQ Questions Set-9

Here is an interesting Python Multiple choice questions Quiz. Attempting this MCQ will help you to evaluate your knowledge and skills.

1.What will be the output of the following Python code?

def mk(x):
def mk1():
print(“Decorated”)
x()
return mk1
def mk2():
print(“Ordinary”)
p = mk(mk2)
p()

a)
Decorated
Decorated
b)
Ordinary
Ordinary
c)
Ordinary
Decorated
d)
Decorated
Ordinary

2. What will be the output of the following Python code?

def ordi():
print(“Ordinary”)
ordi
ordi()
a)Ordinary
b)Error

3. What will be the output of the following Python code?

def f(p, q):
return p%q
print(f(0, 2))
print(f(2, 0))

a)
0
0
b)
Zero Division Error
Zero Division Error
c)
0
Zero Division Error
d)
Zero Division Error
0

4. What will be the output of the following Python code?


def f(x):
def f1(*args, *kwargs): print(“Hello”) return x(args, **kwargs)
return f1
f1()
a) 2
b) 1
c) Error
d) 0

5.What will be the output of the following Python code?

class A:
@staticmethod
def a(x):
print(x)
A.a(100)

a) Error
b) Warning
c) 100
d) No output

6. What will be the output of the following Python code?

l=list(‘HELLO’)
‘first={0[0]}, third={0[2]}’.format(l)
a) ‘first=H, third=L’
b) ‘first=0, third=2’
c) Error
d) ‘first=0, third=L’

7. 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)
a) Error
b) “a=’H’, b=’O’, c=(E, L)”
c) “a=H, b=O, c=[‘E’, ‘L’]”
d) Junk value

8. What will be the output of the following Python code?

hex(255), int(‘FF’, 16), 0xFF
a) [0xFF, 255, 16, 255]
b) (‘0xff’, 155, 16, 255)
c) Error
d) (‘0xff’, 255, 255)

9.  The output of the two codes shown below is the same.

bin((216)-1) ‘{}’.format(bin((216)-1))
a) True
b) False

10. What will be the output of the following Python code?

‘{a}{b}{a}’.format(a=’hello’, b=’world’)
a) ‘hello world’
b) ‘hello’ ‘world’ ‘hello’
c) ‘helloworldhello’
d) ‘hello’ ‘hello’ ‘world’

11. What will be the output of the following Python code?

D=dict(p=’hello’,q=’world’)
‘{p}{q}’.format(**D)
a) Error
b) ‘helloworld’
c) ‘hello world’
d) {‘hello’, ‘world’}

12. What will be the output of the following Python code?

‘The {} side {1} {2}’.format(‘bright’, ‘of’, ‘life’)
a) Error
b) ‘The bright side of life’
c) ‘The {bright} side {of} {life}’
d) No output

13. What will be the output of the following Python code?

‘%.2f%s’ % (1.2345, 99)
a) ‘1.2345’, ‘99’
b) ‘1.2399’
c) ‘1.234599’
d) 1.23, 99

14. What will be the output of the following Python code?

‘%s’ %((1.23,),)
a) ‘(1.23,)’
b) 1.23,
c) (,1.23)
d) ‘1.23’

15. What will be the output of the following Python code snippet?

‘%d %s %g you’ %(1, ‘hello’, 4.0)
a) Error
b) 1 hello you 4.0
c) ‘1 hello 4 you’
d) 1 4 hello you

16. The output of which of the codes shown below will be: ‘There are 4 bluebirds.’?


a)>>> ‘There are %g %d birds.’ %4 %blue
b) >>>‘There are %d %s birds.’ %(4, ‘blue’)
c) >>>‘There are %s %d birds.’ %[4, blue]
d) >>>‘There are %d %s birds.’ 4, blue

17. What will be the output of the following Python code snippet?

x=3.3456789
‘%s’ %x, str(x)
a) Error
b) (‘3.3456789’, ‘3.3456789’)
c) (3.3456789, 3.3456789)
d) (‘3.3456789’, 3.3456789)

18. What will be the output of the following Python code?

s='{0}, {1}, and {2}’
s.format(‘hello’, ‘good’, ‘morning’)
a) ‘hello good and morning’
b) ‘hello, good, morning’
c) ‘hello, good, and morning’
d) Error


19. What will be the output of the following Python code?


print(()or[]or{}or”)
a)()
b)[]
c){}
d)None of the above

20. What will be the output of the following Python code?


print([‘f’, ‘t’]or[bool(‘spam’)])

a) [‘f’, ‘t’]
b)spam
c)’spam’
d)None of the above

Leave a Comment