Python Coding Online Test - MCQ Questions

Welcome to the Python Programming Online Test! This assessment is designed to measure your proficiency in Python, one of the most popular and versatile programming languages today. The test consists of 25 multiple-choice questions, each featuring a Python code snippet that tests various aspects of your Python knowledge—from basic syntax and operations to more advanced features like list comprehensions and function handling.

The questions are designed to challenge and evaluate your ability to interpret Python code and predict outputs accurately. They cover a range of topics, including data types, control structures, functions, exception handling, and more. This will help gauge both your theoretical understanding and practical skills in Python programming.

Before you start, please ensure that you read each question carefully and analyze the given code snippets to choose the most appropriate answer. Detailed explanations are provided for each answer to enhance your learning experience and clarify the reasoning behind each correct response.

Good luck! We hope you find this test engaging and informative and that it helps you assess and improve your Python coding skills.

1. What is the output of the following Python code?

x = 5
y = 3
print(x + y)
a) 8
b) 53
c) 15
d) Syntax error

2. What will the following Python code print?

x = "Hello "
y = "World"
print(x + y)
a) Hello World
b) HelloWorld
c) Hello
d) World

3. What does the following Python code output?

x = [1, 2, 3, 4, 5]
print(x[-1])
a) 1
b) 2
c) 5
d) Error

4. What is the output of the following Python code?

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

5. What does the following Python code print?

print(15 // 4)
a) 3.75
b) 3
c) 4
d) 3.0

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

x = True
y = False
print(x and y)
a) True
b) False
c) None
d) Error

7. What does this Python code output?

x = ['apple', 'banana', 'cherry']
x.pop()
print(x)
a) ['apple', 'banana', 'cherry']
b) ['apple', 'banana']
c) ['banana', 'cherry']
d) ['apple', 'cherry']

8. What will the following Python code snippet output?

x = 5
y = x
y += 2
print(x)
a) 5
b) 7
c) Error
d) None

9. What does the following Python code print?

def test(x, y):
    if x > y:
        return x
    return y
print(test(4, 10))
a) 4
b) 10
c) None
d) Error

10. What is the result of executing the following Python code?

x = "awesome"
def myfunc():
    x = "fantastic"
    print("Python is " + x)
myfunc()
print("Python is " + x)
a) Python is fantastic\nPython is awesome
b) Python is awesome\nPython is fantastic
c) Python is fantastic
d) Python is awesome

11. What will this Python function output?

def multiply(x, y=2):
    return x * y
print(multiply(5, 3))
a) 10
b) 15
c) 5
d) None of these

12. What is the output of the following Python code?

x = [1, 2, 3]
y = x
y.append(4)
print(x)
a) [1, 2, 3]
b) [1, 2, 3, 4]
c) [1, 2, 3, 4, 4]
d) Error

13. What does the following Python code return?

x = lambda a, b: a * b
print(x(5, 6))
a) 5
b) 6
c) 11
d) 30

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

try:
    print(1 / 0)
except ZeroDivisionError:
    print("Error")
a) 1
b) 0
c) Error
d) None

15. What will the following Python code snippet output?

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

16. What does this Python code print?

x = "Hello"
print(x.upper())
a) HELLO
b) hello
c) Hello
d) Error

17. What is the outcome of the following Python code?

x = (1, 2, 3)
x[1] = 10
print(x)
a) (1, 10, 3)
b) (1, 2, 3)
c) Error
d) None of these

18. What will this Python code output?

x = 5
y = 3
print(x ** y)
a) 15
b) 125
c) 8
d) None of these

19. What does the following Python code return?

x = {"apple", "banana", "cherry"}
x.add("orange")
print(x)
a) {"apple", "banana", "cherry", "orange"}
b) {"banana", "cherry", "orange"}
c) {"orange"}
d) Error

20. What is the result of executing the following Python code?

x = [1, 2, 3, 4, 5]
y = [i ** 2 for i in x]
print(y)
a) [1, 2, 3, 4, 5]
b) [1, 4, 9, 16, 25]
c) [1, 4, 6, 8, 10]
d) Error

21. What will the following Python code snippet output?

x = 'hello'
print(x.replace('l', 'p'))
a) heppo
b) heppp
c) hepllo
d) hello

22. What is the output of the following Python code?

print("Hello\nWorld")
a) Hello World
b) HelloWorld

c) Hello

World

d) Hello

\nWorld

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

x = 123
print("%06d" % x)
a) 000123
b) 123000
c) 123
d) 001230

24. What does the following Python code output?

x = [1, 2, 3]
y = x
x.append(4)
print(y)
a) [1, 2, 3]
b) [1, 2, 3, 4]
c) [1, 2, 3, 4, 4]
d) Error

25. What is the result of this Python function?

def is_even(num):
return num % 2 == 0
print(is_even(10))
a) True
b) False
c) None
d) Error

Comments