100 Python Multiple Choice Questions with Answers

 

Here are 100 Python multiple choice questions (MCQs) with 4 options for each and the correct answer indicated at the end of each question:


1. Who developed Python Programming Language?

a) Wick van Rossum
b) Rasmus Lerdorf
c) Guido van Rossum
d) Niene Stom
Answer: c) Guido van Rossum

2. Which type of Programming does Python support?

a) object-oriented programming
b) structured programming
c) functional programming
d) all of the mentioned
Answer: d) all of the mentioned

3. Is Python case sensitive when dealing with identifiers?

a) no
b) yes
c) machine dependent
d) none of the mentioned
Answer: b) yes

4. Which of the following is the correct extension of the Python file?

a) .python
b) .pl
c) .py
d) .p
Answer: c) .py

5. Is Python code compiled or interpreted?

a) Compiled
b) Interpreted
c) Both
d) None
Answer: b) Interpreted

6. Which of the following is not a keyword in Python?

a) assert
b) nonlocal
c) pass
d) eval
Answer: d) eval

7. Which of the following is an immutable data type?

a) List
b) Set
c) Tuple
d) Dictionary
Answer: c) Tuple

8. What is the output of the following code?

print(type(5))

a) <class 'int'>
b) <class 'str'>
c) <class 'float'>
d) <class 'char'>
Answer: a) <class 'int'>

9. What is the output of the following code?

x = 10 y = 50 if x ** 2 > 100: print(x, end=" ") if y < 100: print(y, end=" ")

a) 10 50
b) 50
c) 10
d) None
Answer: b) 50

10. Which of the following functions is a built-in function in Python?

a) factorial()
b) print()
c) sqrt()
d) pow()
Answer: b) print()


11. What is the maximum possible length of an identifier in Python?

a) 16
b) 32
c) 64
d) No fixed length is specified
Answer: d) No fixed length is specified

12. Which of the following statements is correct regarding the object-oriented programming concept in Python?

a) Python supports classes but not objects
b) Python is a partially object-oriented programming language
c) Python is a fully object-oriented programming language
d) Python doesn't support classes
Answer: c) Python is a fully object-oriented programming language

13. What is the output of the following code?

def f(x): return x + 1 f = lambda x: x + 1 print(f(2))

a) 3
b) 2
c) Error
d) None of the above
Answer: a) 3

14. What is the output of the following code?

a = [1, 2, 3] a.append([4, 5]) print(a)

a) [1, 2, 3, 4, 5]
b) [1, 2, 3, [4, 5]]
c) Error
d) None of the above
Answer: b) [1, 2, 3, [4, 5]]

15. What is the output of the following code?

x = [1, 2, 3, 4] print(x[-1])

a) 1
b) 2
c) 3
d) 4
Answer: d) 4


16. Which of the following is used to define a block of code in Python?

a) Curly brackets
b) Parenthesis
c) Indentation
d) Quotation marks
Answer: c) Indentation

17. Which of the following is not a core data type in Python?

a) Lists
b) Dictionary
c) Tuples
d) Class
Answer: d) Class

18. Which keyword is used for function in Python?

a) Function
b) Def
c) Fun
d) Define
Answer: b) Def

19. What is the output of the following code?

x = [1, 2, 3, 4]
print(len(x))

a) 3
b) 4
c) Error
d) None of the above
Answer: b) 4

20. What is the correct syntax to declare a variable in Python?

a) var name
b) let name
c) name = value
d) var: name
Answer: c) name = value


21. Which of the following is used to define a set in Python?

a) {}
b) []
c) ()
d) ""
Answer: a) {}

22. What is the output of the following code?

print("hello"[0])

a) h
b) e
c) l
d) o
Answer: a) h

23. What is the output of the following code?

a = [1, 2, 3] print(a * 2)

a) [2, 4, 6]
b) [1, 2, 3, 1, 2, 3]
c) [1, 4, 9]
d) [2, 3, 4]
Answer: b) [1, 2, 3, 1, 2, 3]

24. How do you create a dictionary in Python?

a) {"key": "value"}
b) ["key", "value"]
c) ("key", "value")
d) None of the above
Answer: a) {"key": "value"}

25. What will the following code print?

d = {"name": "Alice", "age": 25} print(d["name"])

a) Alice
b) 25
c) name
d) Error
Answer: a) Alice


26. Which of the following is not a valid variable name in Python?

a) my_var
b) 123var
c) var123
d) _var
Answer: b) 123var

27. What is the output of the following code?

x = [1, 2, 3] print(x[1:])

a) [1]
b) [2, 3]
c) [1, 2]
d) [3]
Answer: b) [2, 3]

28. What is the purpose of the pass statement in Python?

a) It is used to skip the iteration.
b) It is used to terminate a loop.
c) It is used as a placeholder for future code.
d) It is used to return a value from a function.
Answer: c) It is used as a placeholder for future code.

29. What is the output of the following code?

def func(): return 5 print(func())

a) None
b) 5
c) func
d) Error
Answer: b) 5

30. What will the following code produce?

x = [1, 2, 3, 4, 5] print(x[:])

a) [1, 2, 3, 4, 5]
b) [2, 3, 4, 5]
c) [1]
d) None of the above
Answer: a) [1, 2, 3, 4, 5]

31. What is the output of the following code?

print(2 ** 3)

a) 6
b) 8
c) 9
d) Error
Answer: b) 8

32. What is the output of the following code?

print("hello".upper())

a) Hello
b) HELLO
c) hello
d) Error
Answer: b) HELLO

33. What is the correct way to import a module in Python?

a) import module_name
b) include module_name
c) use module_name
d) insert module_name
Answer: a) import module_name

34. Which of the following is the correct syntax for a for loop in Python?

a) for (i = 0; i < 10; i++)
b) for i in range(10):
c) foreach i in range(10)
d) for(i in range(10))
Answer: b) for i in range(10):

35. What is the output of the following code?

a = "123" b = int(a) print(b + 1)

a) 124
b) 1231
c) Error
d) 1
Answer: a) 124


36. How do you create a comment in Python?

a) // This is a comment
b) /* This is a comment */
c) # This is a comment
d) <!-- This is a comment -->
Answer: c) # This is a comment

37. What is the output of the following code?

a = [1, 2, 3] print(len(a))

a) 2
b) 3
c) 4
d) None of the above
Answer: b) 3

38. How do you check the data type of a variable in Python?

a) type()
b) typeof()
c) dtype()
d) dattype()
Answer: a) type()

39. What is the output of the following code?

a = {1, 2, 3} print(type(a))

a) <class 'list'>
b) <class 'dict'>
c) <class 'tuple'>
d) <class 'set'>
Answer: d) <class 'set'>

40. How do you remove an item from a list in Python?

a) del list[index]
b) list.pop()
c) list.remove(value)
d) All of the above
Answer: d) All of the above


41. What is the output of the following code?

a = [1, 2, 3] a[0] = 5 print(a)

a) [1, 2, 3]
b) [5, 2, 3]
c) Error
d) None of the above
Answer: b) [5, 2, 3]

42. How do you check if a key exists in a dictionary?

a) if key in dict:
b) if key exists dict:
c) if dict.has_key(key):
d) if key.dict:
Answer: a) if key in dict:

43. What is the output of the following code?

print(4 // 2)

a) 2
b) 2.0
c) 1
d) 0
Answer: a) 2

44. What is the output of the following code?

print(4 / 2)

a) 2
b) 2.0
c) 1
d) 0
Answer: b) 2.0

45. How do you write an infinite loop in Python?

a) while True:
b) while(1):
c) while:
d) while x == x:
Answer: a) while True:


46. What is the output of the following code?

x = None if x == None: print("Yes")

a) Yes
b) No
c) Error
d) None of the above
Answer: a) Yes

47. How do you declare a global variable inside a function?

a) Use the global keyword
b) Use the nonlocal keyword
c) Define it normally inside the function
d) Use var keyword
Answer: a) Use the global keyword

48. What is the correct way to concatenate two strings in Python?

a) "Hello" + "World"
b) "Hello".concat("World")
c) join("Hello", "World")
d) "Hello" + join "World"
Answer: a) "Hello" + "World"

49. What is the output of the following code?

x = 10 print(x % 3)

a) 3
b) 1
c) 2
d) 0
Answer: c) 

50. What is the output of the following code?

print(type(True))

a) <class 'bool'>
b) <class 'int'>
c) <class 'str'>
d) <class 'none'>
Answer: a) <class 'bool'>


51. What is the output of the following code?

x = 5 y = "5" print(x == y)

a) True
b) False
c) Error
d) None of the above
Answer: b) False

52. What is the output of the following code?

a = [1, 2, 3, 4] b = a b.append(5) print(a)

a) [1, 2, 3, 4]
b) [1, 2, 3, 4, 5]
c) [5]
d) None of the above
Answer: b) [1, 2, 3, 4, 5]

53. What is the output of the following code?

a = "Hello" print(a[1:4])

a) Hel
b) Hell
c) ell
d) o
Answer: c) ell

54. What will the following code produce?

for i in range(3): print(i)

a) 1 2 3
b) 0 1 2
c) 2 1 0
d) None of the above
Answer: b) 0 1 2

55. Which method is used to sort a list in Python?

a) list.sort()
b) sort(list)
c) sort()
d) sorted()
Answer: a) list.sort()


56. What is the output of the following code?

a = 3 b = 5 print(a * b)

a) 8
b) 15
c) Error
d) None of the above
Answer: b) 15

57. How do you get the length of a string in Python?

a) len(string)
b) string.len()
c) length(string)
d) string.length()
Answer: a) len(string)

58. Which of the following data types is mutable in Python?

a) String
b) List
c) Tuple
d) Integer
Answer: b) List

59. What is the output of the following code?

print(10 < 20 and 5 > 3)

a) True
b) False
c) None
d) Error
Answer: a) True

60. Which of the following can be a variable name in Python?

a) var-name
b) var_name
c) var name
d) 1var
Answer: b) var_name

61. How do you declare a multi-line string in Python?

a) Triple quotes (''' or """)
b) Double quotes (" ")
c) Single quotes (' ')
d) Using \n for new line
Answer: a) Triple quotes (''' or """)

62. What is the output of the following code?

a = [1, 2, 3, 4] print(a[::-1])

a) [4, 3, 2, 1]
b) [1, 2, 3, 4]
c) [4, 1, 3, 2]
d) Error
Answer: a) [4, 3, 2, 1]

63. Which keyword is used for exception handling in Python?

a) try
b) except
c) finally
d) All of the above
Answer: d) All of the above

64. What is the output of the following code?

a = (1, 2, 3, 4) print(a[2])

a) 1
b) 2
c) 3
d) 4
Answer: c) 3

65. Which function converts an object to a string in Python?

a) str()
b) int()
c) string()
d) to_str()
Answer: a) str()

66. What is the output of the following code?

x = [1, 2, 3] y = x.copy() y.append(4) print(x)

a) [1, 2, 3]
b) [1, 2, 3, 4]
c) [4]
d) None of the above
Answer: a) [1, 2, 3]

67. What is the output of the following code?

x = [1, 2, 3] x.insert(1, 4) print(x)

a) [1, 4, 2, 3]
b) [1, 2, 3, 4]
c) [4, 1, 2, 3]
d) [1, 2, 4, 3]
Answer: a) [1, 4, 2, 3]

68. What is the output of the following code?

a = "Hello" print(a[-1])

a) H
b) o
c) e
d) l
Answer: b) o

69. Which of the following is a valid dictionary declaration?

a) dict = {1: "a", 2: "b"}
b) dict = {1, 2, 3}
c) dict = [1: "a", 2: "b"]
d) dict = (1, 2, 3)
Answer: a) dict = {1: "a", 2: "b"}

70. What is the correct way to open a file for writing in Python?

a) open(file, "w")
b) open(file, "r")
c) open(file, "rw")
d) open(file, "a")
Answer: a) open(file, "w")


71. What is the output of the following code?

x = "123" y = int(x) print(y + 1)

a) 1231
b) 124
c) 1
d) Error
Answer: b) 124

72. What is the output of the following code?

x = [1, 2, 3, 4] print(x[1:])

a) [1]
b) [2, 3, 4]
c) [1, 2]
d) [1, 2, 3, 4]
Answer: b) [2, 3, 4]

73. How do you create a tuple in Python?

a) (1, 2, 3)
b) [1, 2, 3]
c) {1, 2, 3}
d) tuple(1, 2, 3)
Answer: a) (1, 2, 3)

74. Which of the following is not a built-in function in Python?

a) max()
b) print()
c) sqrt()
d) len()
Answer: c) sqrt()

75. What is the output of the following code?

a = [1, 2, 3] b = [4, 5, 6] print(a + b)

a) [1, 2, 3, 4, 5, 6]
b) [1, 2]
c) Error
d) None of the above
Answer: a) [1, 2, 3, 4, 5, 6]

76. What is the output of the following code?

x = 10 if x > 5: print("Greater") else: print("Lesser")

a) Greater
b) Lesser
c) Error
d) None of the above
Answer: a) Greater

77. How do you get a random number in Python?

a) random()
b) random.randint()
c) random.random()
d) random.range()
Answer: c) random.random()

78. What is the output of the following code?

a = "Python" print(a[1:4])

a) Pyt
b) yth
c) tho
d) Pyth
Answer: b) yth

79. Which of the following can be used to handle exceptions in Python?

a) try
b) except
c) finally
d) All of the above
Answer: d) All of the above

80. What is the output of the following code?

a = [1, 2, 3, 4] b = a[::-1] print(b)

a) [4, 3, 2, 1]
b) [1, 2, 3, 4]
c) [1, 2]
d) Error
Answer: a) [4, 3, 2, 1]


81. What does the is keyword compare in Python?

a) Value of two variables
b) Memory location of two objects
c) Types of two variables
d) None of the above
Answer: b) Memory location of two objects

82. Which of the following methods can be used to read the contents of a file in Python?

a) read()
b) readline()
c) readlines()
d) All of the above
Answer: d) All of the above

83. What is the output of the following code?

x = [1, 2, 3, 4] print(len(x))

a) 4
b) 3
c) 5
d) Error
Answer: a) 4

84. What is the output of the following code?

a = "Hello" print(a.lower())

a) hello
b) HELLO
c) Hello
d) hElLo
Answer: a) hello

85. What is the result of the following code?

x = {"apple", "banana", "cherry"} print(type(x))

a) <class 'list'>
b) <class 'tuple'>
c) <class 'set'>
d) <class 'dict'>
Answer: c) <class 'set'>


86. What is the output of the following code?

x = "Python" print(x.replace("P", "J"))

a) Python
b) Jython
c) JyJhon
d) None of the above
Answer: b) Jython

87. How do you define a function in Python?

a) def function_name():
b) function function_name():
c) func function_name():
d) define function_name():
Answer: a) def function_name():

88. What is the correct syntax for a lambda function?

a) lambda arguments: expression
b) lambda(arguments): expression
c) function lambda(arguments): expression
d) def lambda(arguments): expression
Answer: a) lambda arguments: expression

89. What is the output of the following code?

print(len("Hello World"))

a) 11
b) 10
c) 12
d) 9
Answer: a) 11

90. How do you convert a string to an integer in Python?

a) int()
b) str()
c) float()
d) None of the above
Answer: a) int()


91. What does the break statement do in Python?

a) Exits the current loop
b) Continues the current loop
c) Stops the program
d) None of the above
Answer: a) Exits the current loop

92. What is the output of the following code?

for i in range(5): if i == 3: break print(i)

a) 0 1 2
b) 0 1 2 3 4
c) 3
d) 1 2 3
Answer: a) 0 1 2

93. How do you create a set in Python?

a) {1, 2, 3}
b) [1, 2, 3]
c) (1, 2, 3)
d) set[1, 2, 3]
Answer: a) {1, 2, 3}

94. What is the output of the following code?

x = "Hello" print(x[1:3])

a) He
b) ll
c) el
d) lo
Answer: c) el

95. What is the output of the following code?

x = [1, 2, 3] print(x[0])

a) 1
b) 2
c) 3
d) None
Answer: a) 1


96. What is the correct syntax to check if a key exists in a dictionary?

a) key in dictionary
b) dictionary.key
c) key.exists(dictionary)
d) key.dictionary()
Answer: a) key in dictionary

97. How do you create a list in Python?

a) [1, 2, 3]
b) {1, 2, 3}
c) (1, 2, 3)
d) set[1, 2, 3]
Answer: a) [1, 2, 3]

98. What is the output of the following code?

x = [1, 2, 3, 4] x.remove(2) print(x)

a) [1, 2, 3]
b) [1, 3, 4]
c) Error
d) [1, 2, 4]
Answer: b) [1, 3, 4]

99. What is the output of the following code?

print(min(3, 5, 1, 9))

a) 9
b) 5
c) 3
d) 1
Answer: d) 1

100. What is the output of the following code?

x = "abcd" print(x.upper())

a) abcd
b) ABCD
c) aBCD
d) None of the above
Answer: b) ABCD



Tags: basic python mcqs, advanced python mcqs, programming-questions,questions with answers,interview-questions,python-programming,python tutorial,python interview questions,python for beginners,Python Programming,

Post a Comment

Previous Post Next Post