Looking For Anything Specific?

Python MCQs


16. What is the output of print(list(range(3)))?
a) [0, 1, 2]
b) [1, 2, 3]
c) [0, 1, 2, 3]
d) Error

Answer: a) [0, 1, 2]


17. Which of the following methods adds an element to a set?
a) append()
b) insert()
c) add()
d) extend()

Answer: c) add()


18. What is the output of print(3 * 'abc')?
a) abcabcabc
b) 3abc
c) abc3
d) Error

Answer: a) abcabcabc


19. How do you create an empty set in Python?
a) {}
b) []
c) set()
d) ()

Answer: c) set()


20. What is the output of 5 == 5.0?
a) True
b) False
c) Error
d) None

Answer: a) True


21. Which of the following is used to create a tuple?
a) []
b) {}
c) ()
d) <>

Answer: c) ()


22. What is the result of 10 // 3?
a) 3
b) 3.33
c) 4
d) Error

Answer: a) 3


23. Which keyword is used to create a class in Python?
a) function
b) class
c) def
d) create

Answer: b) class


24. What does not True evaluate to?
a) True
b) False
c) None
d) Error

Answer: b) False


25. What is the output of print(2 ** 3)?
a) 5
b) 6
c) 8
d) Error

Answer: c) 8


26. What is the correct way to open a file in write mode?
a) open('file.txt', 'r')
b) open('file.txt', 'w')
c) open('file.txt', 'a')
d) open('file.txt', 'x')

Answer: b) open('file.txt', 'w')


27. What is the output of print(4 > 3 and 2 < 5)?
a) True
b) False
c) None
d) Error

Answer: a) True


28. What will print('Hello'[1:4]) return?
a) Hell
b) ell
c) lo
d) Error

Answer: b) ell


29. What does max([1, 2, 3]) return?
a) 1
b) 2
c) 3
d) Error

Answer: c) 3


30. Which of the following methods removes the last element from a list?
a) pop()
b) delete()
c) remove()
d) discard()

Answer: a) pop()



Post a Comment

0 Comments