More than 100+ Python MCQs with Answers.
1. Who developed Python Programming Language?
A) Wick van Rossum
B) Rasmus Lerdorf
C) Guido van Rossum
D) Niene Stom
View Answer
Answer: C
2. Which of the following is not a keyword in Python?
A) and
B) as
C) assert
D) on
View Answer
Answer: D
3. Which of the following is the correct extension of the Python file?
A) .python
B) .pl
C) .py
D) .p
View Answer
Answer: C
4. Which of the following is not a valid variable name in Python?
A) my_variable
B) 2nd_variable
C) variable2
D) None of the above
View Answer
Answer: B
5. Is Python case sensitive when dealing with identifiers?
A) no
B) yes
C) machine dependent
D) none of the mentioned
View Answer
Answer: B
6. Which among the following statement is true for the python program?
A) Python is an interpreted Language
B) Python is a high-level programming Language
C) Python is an object-oriented Language
D) All of the above
View Answer
Answer: D
7. What is the result of the following code?
x = "hello"
y = "world"
print(x + y)
A) helloworld
B) hello world
C) Error
D) None of the above
View Answer
Answer: A
8. What is the output of the following code?
print(2 + 3 * 4)
A) 14
B) 20
C) 11
D) None of the above
View Answer
Answer: A
9. Which of the following is used to define a block of code in Python language?
A) Indentation
B) Key
C) Brackets
D) All of the mentioned
View Answer
Answer: A
10. What is the output of the following code?
x = 0
while x < 20:
x = x+3
print(x)
A) 19
B) 21
C) 18
D) 20
View Answer
Answer: B
11. Python is developed using which language?
A) C programming
B) C++ programming
C) Java Programming
D) None of the above
View Answer
Answer: A
12. Python’s first version was released in which year?
A) 1990
B) 1991
C) 1992
D) 1993
View Answer
Answer: B
13. What is the output of the following code?
x = [1, 2, 3]
print(x.pop())
A) [1, 2]
B) [2, 3]
C) 3
D) [1, 3]
View Answer
Answer: C
14. What is the output of the following code?
x = [1, 2, 3]
y = x
y[1] = 4
print(x)
A) [1, 2, 3]
B) [1, 4, 3]
C) [4, 2, 3]
D) None of the above
View Answer
Answer: B
15. What is the value of the following expression?
print(2**3**2)
A) 64
B) 256
C) 512
D) 12
View Answer
Answer: C
16. What is the output of the following code?
x = 5
y = 3
print(x % y)
A) 1
B) 2
C) 8
D) 5
View Answer
Answer: B
17. What is the output of the following code?
x = [1, 2, 3]
x.remove(2)
print(x)
A) [2, 3]
B) [1, 3]
C) [1, 2]
D) None of the above
View Answer
Answer: B
18. How would you create a tuple in Python?
A) { }
B) [ ]
C) ( )
D) tup()
View Answer
Answer: C
19. What is the output of the following code?
x = [1, 2, 3]
y = x
y = [4, 5, 6]
print(x)
A) [1, 2, 3]
B) [4, 5, 6]
C) [1, 2, 3, 4, 5, 6]
D) None of the above
View Answer
Answer: A
20. What is the function used to check the type of a variable in Python?
A) type()
B) var_type()
C) check_type()
D) None of the above
View Answer
Answer: A
21. IDLE stands for?
A) Information Development and Learning Environment
B) Informative Development and Learning Environment
C) Integrated Development and Learning Environment
D) None of the above
View Answer
Answer: C
22. Evaluate the expression given below if A = 16 and B = 15
A = 16
B = 15
print(A % B // A)
A) 0.0
B) 0
C) 0.1
D) 1
View Answer
Answer: B
23. What is the output of the following code?
x = {"a": 1, "b": 2}
x.update({"c": 3})
print(x)
A) {“a”: 1, “b”: 2, “c”: 3}
B) {“c”: 3, “a”: 1, “b”: 2}
C) {“c”: 3}
D) None of the above
View Answer
Answer: A
24. Which of the following is a built-in function in Python?
A) length()
B) printf()
C) print()
D) power()
View Answer
Answer: C
25. Which of the following expression result in an error?
A) float(’12’)
B) int(’12’)
C) float(‘12.5’)
D) int(‘12.5’)
View Answer
Answer: D
26. What is the output of the following code?
x = {"a": 1, "b": 2, "c": 3}
print(x.get("d"))
A) d
B) None
C) Error
D) 3
View Answer
Answer: B
27. What is the output of the following code?
x = 123
for i in x:
print(i)
A) 1 2 3
B) 123
C) Infinity loop
D) Error
View Answer
Answer: D
28. What is the output of the following code?
x = [1, 2, 3]
y = x * 3
print(y)
A) [1, 2, 3, 1, 2, 3, 1, 2, 3]
B) [3, 3, 3]
C) [1, 6, 9]
D) Error
View Answer
Answer: A
29. What is the output of the following code?
x = {"a": 1, "b": 2}
y = x.keys()
print(y)
A) [1, 2]
B) [“a”, “b”]
C) {“a”, “b”}
D) (“a”, “b”)
View Answer
Answer: B
30. As what datatype are the *args stored, when passed into a function?
A) List
B) Dictionary
C) Tuple
D) None of the above
View Answer
Answer: C
31. Which of the following statement prints the shown output below?
hello\example\text.text
A) print(“hello\example\text.text”)
B) print(“hello\\example\\text.text”)
C) print(“hello\”example\”text.text”)
D) print(“hello”\example”\text.text”)
View Answer
Answer: B
32. What is the output of the following code?
x = {"a": 1, "b": 2}
y = x.values()
print(y)
A) [1, 2]
B) (1, 2)
C) {1,2}
D) (“a”, “b”)
View Answer
Answer: A
33. What is the output of the following code?
x = [1, 2, 3, 4, 5]
y = x[::-1]
print(y)
A) [1, 2, 3, 4, 5]
B) [5, 4, 3, 2, 1]
C) [1, 5, 4, 3, 2]
D) None of the above
View Answer
Answer: B
34. What is the output of the following code?
x = {"a": 1, "b": 2, "c": 3}
y = x.items()
print(y)
A) {“a”: 1, “b”: 2, “c”: 3}
B) [(“a”, 1), (“b”, 2), (“c”, 3)]
C) [“a”, “b”, “c”]
D) None of the above
View Answer
Answer: B
35. What will be the value of the following Expression?
print((5>10) and (10<5) or (3<18) and (8<18))
A) False
B) True
C) Error
D) None of the above
View Answer
Answer: B
36. What is the maximum length of a Python identifier?
A) 32
B) 16
C) 128
D) Not Fixed length specified
View Answer
Answer: D
37. What is the output of the following code?
print(2**3 + (5 + 6)**(1 + 1))
A) 129
B) 8
C) 121
D) None of the above
View Answer
Answer: A
38. A token is also called a _____________.
A) Literals
B) Lexical unit
C) Atomic unit
D) Names
View Answer
Answer: B
39. What is the output of the following code?
def solve(a):
l1 = [1, 3, 5]
l1 = [2, 2, 5]
print(l1)
solve(l1)
print(l1)
A) [2,2,5] , [1,3,5]
B) [2,2,5] , [2,2,5]
C) [1,3,5], [2,2,5]
D) None of the above
View Answer
Answer: B
40. What is the output of the following code?
x = "hello"
y = x.join(["a", "b", "c"])
print(y)
A) ahellobhelloc
B) helloahellobc
C) abc
D) Error
View Answer
Answer: A
41. What is the output of the following code?
x = "hello"
y = x.replace("l", "L")
print(y)
A) heLLo
B) heLlo
C) HeLlo
D) None of the above
View Answer
Answer: A
42. What is the output of the following code?
x = "hello"
y = x.find("l")
print(y)
A) -2
B) 2
C) 3
D) -1
View Answer
Answer: B
43. What is the output of the following code?
x = [1, 2, 3]
y = x.pop(1)
print(y)
A) [1,3]
B) [2,3]
C) 2
D) None of the above
View Answer
Answer: C
44. What is the output of the following code?
x = [1, 2, 3]
y = x.remove(2)
print(y)
A) [1,3]
B) [2,3]
C) 2
D) None
View Answer
Answer: D
45. What will be the type of the variable sorted_numbers
in the below code snippet?
nums = (4, 7, 19, 2, 89, 45, 72, 22)
sorted_numbers = sorted(nums)
print(type(sorted_numbers))
A) List
B) Tuple
C) String
D) Int
View Answer
Answer: A
46. What is the output of the following code?
from math import *
a = 2.19
b = 3.999999
c = -3.30
print(int(a), floor(b), ceil(c), fabs(c))
A) 2 3 -3 3.3
B) 2 4 -3 3
C) 2 3 -4 3.3
D) 2 3 -3 -3.3
View Answer
Answer: A
47. Which of the following function accept only integers as an argument?
A) ord()
B) min()
C) chr()
D) type()
View Answer
Answer: C
48. Which of the following statement is correct for the “and” operator?
A) Python evaluates the second argument only if the first one is False
B) Python evaluates the second argument only if the first one is True
C) Python evaluates True if any one of the arguments is True
D) Python only evaluates False if anyone argument is True
View Answer
Answer: B
49. The Error produced by the below code is:
a = None
print(a+1)
A) Syntax Error
B) Type Error
C) Value Error
D) Name Error
View Answer
Answer: B
50. What is the output of the following code?
a = 1
while i<=10:
i+=1
print(i)
A) 10
B) 19
C) 11
D) None of the above
View Answer
Answer: D
51. What will be the value of the following expression?
print(0.1 + 0.2 == 0.3)
A) True
B) False
C) Machine Dependent
D) Error
View Answer
Answer: B
52. What will be the Output of the following code?
x = "abcdef"
i = "i"
while i in x:
print(i)
A) a b c d e f
B) abcdef
C) i i i i i…
D) No Output
View Answer
Answer: D
53. What will be the Output of the following code?
a = 547
while a > 0:
a = a//10
print(a,end=" ")
A) 7 4 5
B) 547 54 5
C) 54 5 0
D) No Output
View Answer
Answer: C
54. How a>b>c will be interpreted by python?
A) a>b or b>c
B) a>b not b>c
C) a>b and b>c
D) None of the above
View Answer
Answer: C
55. Why are local variable names beginning with an underscore discouraged?
A) they confuse the interpreter
B) they are used to indicate private variables of a class
C) they are used to indicate global variables
D) they slow down the execution
View Answer
Answer: B
56. which of the following is an invalid statement?
A) num = 1,000,000
B) x y z = 1 2 3
C) x,y,z = 1,2,3
D) x_y_z = 1,000,000
View Answer
Answer: B
57. Boolean type is a subtype of integer data type in python:
A) True
B) False
View Answer
Answer: A
58. What will be the Output of the following code?
print(22//3+3/3)
A) 8
B) 8.0
C) 8.3
D) 8.33
View Answer
Answer: B
59. What will be the Output of the following code?
for i in range(2):
for j in range(2):
print(j,end=",")
A) 0,1,0,1
B) 0 1 0 1
C) 0,0,1,1
D) 0,1,0,1,
View Answer
Answer: D
60. What will be the Output of the following code?
a = 0
b = 5
x = (a&b) (a&a) (a|b)
print('x')
A) 0
B) 5
C) x
D) None of the above
View Answer
Answer: D
61. Which of the following statements are correct?
- Python is a high-level programming language
- Python is an interpreted language
- Python is a compiled language
- Python program is compiled before it is interpreted
A) 1,2
B) 1,4
C) 2,3
D) 2,4
View Answer
Answer: B
62. What will be the result of following python the code snippet after execution?
a = input('Enter Number: ')
b = input('Enter Second Number: ')
c = a+b
print(c)
NOTE: Assume variable a
as 1 and variable b
as 6
A) 16
B) 7
C) 61
D) None of the above
View Answer
Answer: A
63. What will be the Output of the following code?
a = [5,10,15,20,25]
k = 1
i = a[1]+1
j = a[2]+1
m = a[k+1]
print(i,j,m)
A) 1 15 12
B) 11 16 15
C) 11 15 15
D) 16 11 15
View Answer
Answer: B
64. List AL
is defined as follow: AL = [1,2,3,4,5]
Which of the following statements removes the middle element 3 from it so the list AL
become [1,2,4,5]
A) del a[2]
B) a[2:3] = []
C) a[2:2] = []
D) None of the above
View Answer
Answer: D
65. What will be the Output of the following code?
A = [1,2,3,9,5,6,7]
print(A[1:4:-2])
A) [2,6,5]
B) [2,9]
C) [ ]
D) Error
View Answer
Answer: C
66. Of what data type is the object below?
L = 78,43,'diya',10
print(type(L))
A) List
B) Dictionary
C) Tuple
D) Error
View Answer
Answer: C
67. What will be the Output of the following code?
def solve(a, b):
return b if a == 0 else solve(b % a, a)
print(solve(20, 50))
A) 10
B) 20
C) 50
D) 1
View Answer
Answer: A
68. What will be the Output of the following code?
def func():
global value
value = "Local"
value = "Global"
func()
print(value)
A) Local
B) Global
C) None
D) Can not be predicted
View Answer
Answer: A
69. When was Python 3.0 released?
A) 3 December 2010
B) 5 December 2008
C) 4 December 2008
D) 3 December 2008
View Answer
Answer: D
70. Function can be written in ______________ ways
A) One
B) Two
C) Three
D) Four
View Answer
Answer: D
71. Execution of any Python Program begins with _____________.
A) Function
B) __main__
C) Module
D) None of the above
View Answer
Answer: B
72. _____________ is the value that is passed to the function and ___________ is the value that is being received.
A) function, module
B) argument, parameter
C) parameter, argument
D) None of the above
View Answer
Answer: B
73. Python function by default follow the following argument system:
A) Name Argument
B) Positional Argument
C) Default Argument
D) None of the above
View Answer
Answer: B
74. What will be the Output of the following code?
def abc(a=1,b=2,c=3):
print(a+b+c)
abc(5)
abc(5,10)
abc(5,10,15)
A) 6,6,6
B) 10,18,25
C) 18,10,30
D) 10,18,30
View Answer
Answer: D
75. Consider the following function definition:
def interest(prin,cc,time=2,rate=0.09):
return prin*time*rate
which is a valid function call:
A) interest(rate=0.05,5000,3)
B) interest(5000,3,rate=0.05)
C) interest(5000,prin=300,56)
D) None of the above
View Answer
Answer: B
76. Function that returns some value is called:
A) Fruitful Function
B) Void Function
C) Non-void Function
D) None of the above
View Answer
Answer: A
77. What will be the output of the following code:
a = 5
def abcd():
print(a)
adbd()
A) 5
B) 0
C) Error
D) None of the above
View Answer
Answer: C
78. What will be the output of the following code:
a = 5
def abcd():
global a
print(a)
a+=5
abcd()
print(a)
A) 5,10
B) 10,5
C) 5,5
D) None of the above
View Answer
Answer: A
79. the values being passed through a function call statement are called___________.
A) Formal argument
B) Actual argument
C) both a & b
D) None of the above
View Answer
Answer: B
80. Python resolves the scope of a name using ___________ rule.
A) Global Rule
B) Local Rule
C) LEGB Rule
D) None of the above
View Answer
Answer: C
81. LEGB stands for ____________________?
A) Local Elegant Globe Business
B) Local Enclosing Global Buit-in
C) Local Enclosed Global Buit-in
D) Local Enclosed Global Business
View Answer
Answer: B
82. Find the output of the following code:
def add(a,b,c):
print(a+b+c)
def multiply(a,b,c):
return a*b*c
m = add(1,2,3)
n = multiply(1,2,3)
print(m,n)
A) 6 6
B) 6
C) 6, None 6
D) None of the above
View Answer
Answer: C
83. In Python, parameter and arguments are the same thing.
A) True
B) False
View Answer
Answer: B
84. ASCII code for “0” is ____________.
A) 97
B) 65
C) 48
D) None of the above
View Answer
Answer: C
85. Name the file that needs specific programs to access its contents.
A) CSV file
B) Text file
C) Binary file
D) None of the above
View Answer
Answer: C
86. Given the file abc.png, which of the following is the correct way to open the file for reading as a buffered binary file?
A) open(“abc.png”)
B) open(“abc.png”, “r”)
C) open(“abc.png”, “rbin”)
D) open(“abc.png”, “rb”)
View Answer
Answer: D
87. What is the use of seek() method in files?
A) Sets the file’s current position at the offset.
B) Sets the file’s current position within the file.
C) Sets the file’s previous position at the offset.
D) Return the position of the offset.
View Answer
Answer: B
88. The process to convert Structure (list/tuple etc) to Byte stream is called ____________.
A) Pickling
B) Unpickling
C) Both
D) None of the above
View Answer
Answer: A
89. Which function takes two arguments?
A) load()
B) dump()
C) Both
D) None of the above
View Answer
Answer: B
90. Which file mode can be used to modify the file content?
A) r
B) w
C) a
D) r+
View Answer
Answer: C
91. Identify the correct statement to open a file:
A) f = open(“D:\\myfolder\\naman.txt”)
B) f = open(“D:\myfolder\naman.txt”)
C) f = open(“D:myfolder#naman.txt”)
D) None of the above
View Answer
Answer: A
92. EOL stand for _____________.
A) End Of Location
B) End Of Lines
C) End Of List
D) End Of Line
View Answer
Answer: D
93. In F = open(“myfile.txt”), name of file object is:
A) open
B) myfile.txt
C) F
D) F = open()
View Answer
Answer: C
94. What does strip() function do?
A) Removes the trailing or leading spaces, if any
B) Remove the file object
C) Delete the file object
D) Removes all the spaces between words
View Answer
Answer: A
95. readlines() gives the output as:
A) Sets
B) Tuple
C) String
D) List
View Answer
Answer: D
96. Which function reads the leading and trailing spaces along with trailing newline character (‘\n’) also while reading the line?
A) readlines()
B) readline()
C) read()
D) flush()
View Answer
Answer: A
97. Which mode is used to retain its previous data and allowing to add new data?
A) write mode
B) read mode
C) open mode
D) append mode
View Answer
Answer: D
98. Sometimes the last lap of data remains in the buffer and is not pushed onto disk until a __________ operation is performed.
A) dump()
B) close()
C) load()
D) open()
View Answer
Answer: B
99. In _____________ mode, if the file does not exist, then the file is created.
A) append mode
B) read mode
C) write mode
D) a & c
E) a & b
View Answer
Answer: A
100. The extension of binary files is:
A) .b
B) .dat
C) .csv
D) .binary
View Answer
Answer: B
101. To write data in Binary file we use which method?
A) load()
B) dump()
C) write()
D) writebin()
View Answer
Answer: B
102. What will be the output of the following code:
def abc():
return pass
print(abc())
A) None
B) pass
C) SyntaxError
D) None of the above
View Answer
Answer: C