Python Coding MCQ Questions and Answers

Welcome to Python Programming Coding MCQ Questions. Here, we present 20 MCQs (Multiple-Choice Questions) with code snippets to test your understanding of Python programming coding and logical stills. Let's get started!

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

print("Hello World"[::-1])
a) dlroW olleH
b) Hello World
c) d
d) Error

2. What does this Python code output?

x = 8
y = 3
print(x // y)
a) 2.67
b) 2
c) 3
d) None of the above

3. What will this Python script print?

a = [1, 2, 3]
b = a
b[1] = 4
print(a)
a) [1, 2, 3]
b) [1, 4, 3]
c) [4, 2, 3]
d) TypeError

4. Consider the following Python code. What will it print?

x = 10
def change():
    global x
    x = 20
change()
print(x)
a) 10
b) 20
c) NameError
d) None

5. What is the output of the following Python function?

def f(x, l=[]):
    for i in range(x):
        l.append(i*i)
    print(l)
f(2)
f(3, [3,2,1])
f(3)
a) [0, 1, 0, 1, 4], [3, 2, 1, 0, 1, 4], [0, 1, 0, 1, 4, 0, 1, 4]
b) [0, 1], [3, 2, 1, 0, 1, 4], [0, 1, 4]
c) [0, 1], [3, 2, 1, 0, 1, 4], [0, 1, 0, 1, 4]
d) [0, 1], [3, 2, 1, 0, 1, 4], [0, 1, 0, 1, 4, 0, 1, 4]

6. What will the following Python code output?

x = "abc"
for i in x:
    x.upper()
print(x)
a) ABC
b) abc
c) Abc
d) None

7. Consider the following Python code. What is its output?

x = 1
y = 2
print(x == y, x != y)
a) True True
b) False True
c) True False
d) False False

8. What does this Python code print?

a = "Python"
b = "Programming"
print(a + " " + b)
a) Python Programming
b) PythonProgramming
c) TypeError
d) None

9. What will the following Python code print?

a = 5
b = a
a = 3
print(b)
a) 5
b) 3
c) None
d) Error

10. Analyze the following Python code. What is the output?

i = 0
while i < 3:
    i += 1
    if i == 2:
        break
print(i)
a) 1
b) 2
c) 3
d) 4

11. What will this code snippet print?

list = [1, 2, 3]
list.append(4)
print(list.pop(0))
print(list)
a) 1, [2, 3, 4]
b) 4, [1, 2, 3]
c) 1, [1, 2, 3, 4]
d) 4, [2, 3, 4]

12. What does the following Python code output?

x = 5
def add():
    global x
    x += 1
    return x
print(add())
a) 5
b) 6
c) 7
d) None

13. What is the output of the following Python program?

x = 'global'
def outer():
    x = 'outer'
    def inner():
        nonlocal x
        x = 'inner'
        print(x)
    inner()
    print(x)
outer()
print(x)
a) inner, outer, global
b) inner, inner, global
c) inner, inner, outer
d) global, outer, inner

14. What does the following Python code snippet output?

x = [1, 2, 3]
y = x
y += [4, 5]
print(x)
a) [1, 2, 3]
b) [1, 2, 3, 4, 5]
c) [4, 5]
d) TypeError

15. Analyze the Python code below. What will it output?

def func(x):
    return x * x
print(func(5))
a) 25
b) 10
c) 5
d) None

16. What is the output of this Python code?

for i in range(5):
    if i == 3:
        continue
print(i)
a) 0 1 2 4
b) 0 1 2 3 4
c) 0 1 2 3
d) 1 2 4

17. Consider the following Python program. What will it print?

x = 10
y = 20
print('x > y is', x > y)
a) x > y is True
b) x > y is False
c) True
d) False

18. What does the following Python code output?

a = "Python"
b = "Programming"
print(a[1] + b[-1])
a) Po
b) yP
c) ym
d) PythonProgramming

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

def make_multiplier(x):
    def multiplier(n):
        return x * n
    return multiplier
times3 = make_multiplier(3)
times5 = make_multiplier(5)
print(times3(times5(2)))
a) 6
b) 10
c) 30
d) 15

20. What does this code snippet output?

x = True
y = False
print('x and y is', x and y)
a) x and y is True
b) x and y is False
c) True
d) False

Comments