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 : ['Hello,', 'World!']
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 : Both a and b
What is the output of print("Hello".replace("l", "r"))?
1) Herro
2) Hello
3) Error
4) None
Answer : Herro
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 : class MyError(Exception):