Learn Python MCQs

Prepare Python MCQs (Multiple choice Questions) for exam and job interviews.

What is the output of print("Hello, World!".split(" "))?

1) ['Hello,', 'World!']

2) ['Hello', 'World!']

3) Error

4) ['Hello,', 'World!']

Answer : Option 1

How do you get a random number in Python?

1) import random; random.randint(1, 10)

2) random.randint(1, 10)

3) random.random()

4) Both a and b

Answer : Option 1

What is the output of print("Hello".replace("l", "r"))?

1) Herro

2) Hello

3) Error

4) None

Answer : Option 1

How do you create a custom exception in Python?

1) class MyError(Exception):

2) def MyError(Exception):

3) class MyError:

4) None of the above

Answer : Option 1