MCQ On Python
MCQ On Python
* MCQ Questions
1. Is Python case sensitive when dealing with identifiers?
a) yes
b) no
c) machine dependent
d) none of the mentioned
Answer: a
Explanation: Case is always significant.
15. What will be the output of the following Python code snippet?
d = {"john":40, "peter":45}
a) “john”, 40, 45, and “peter”
b) “john” and “peter”
c) 40 and 45
d) d = (40:”john”, 45:”peter”)
Answer: b
Explanation: Dictionaries appear in the form of keys and values.
16. What will be the output of the following Python code snippet?
d = {"john":40, "peter":45}
"john" in d
a) True
b) False
c) None
d) Error
Answer: a
Explanation: In can be used to check if the key is int dictionary.
17. What will be the output of the following Python code snippet?
d1 = {"john":40, "peter":45}
d2 = {"john":466, "peter":45}
d1 == d2
a) True
b) False
c) None
d) Error
Answer: b
Explanation: If d2 was initialized as d2 = d1 the answer would be true.
18. What will be the output of the following Python code snippet?
d1 = {"john":40, "peter":45}
d2 = {"john":466, "peter":45}
d1 > d2
a) True
b) False
c) Error
d) None
Answer: c
Explanation: Arithmetic > operator cannot be used with dictionaries.
a) [2, 3, 9]
b) [1, 2, 4, 3, 8, 9]
c) [1, 4, 8]
d) (1, 4, 8)
Answer: c
Explanation: Execute in the shell to verify.
a) 40
b) 45
c) “john”
d) “peter”
Answer: a
Explanation: Execute in the shell to verify.
a) (1, 2, 1, 2)
b) [1, 2, 1, 2]
c) (1, 1, 2, 2)
d) [1, 1, 2, 2]
Answer: a
Explanation: * operator concatenates tuple.
EXTRA QUESTIONS:
Q. Who developed the Python language?
1. Zim Den
2. Guido van Rossum
3. Niene Stom
4. Wick van Rossum
Answer: (b) Guido van Rossum
Explanation: Python language was developed by Guido van Rossum in the Netherlands.
Q. Which one of the following is the correct extension of the Python file?
1. .py
2. .python
3. .p
4. None of these
Answer: (a) .py
Explanation: ".py" is the correct extension of the Python file.
Q. What do we use to define a block of code in Python language?
1. Key
2. Brackets
3. Indentation
4. None of these
Answer: (c) Indentation
Explanation: Python uses indentation to define blocks of code. Indentations are simply
spaces or tabs used as an indicator that is part of the indent code child. As used in curly
braces C, C++, and Java.
Q. Which character is used in Python to make a single line comment?
1. /
2. //
3. #
4. !
Answer: (c) #
Explanation: "#" character is used in Python to make a single-line comment.
Q. Which of the following is not a keyword in Python language?
1. val
2. raise
3. try
4. with
Answer: (a) val
Explanation: "val" is not a keyword in python language.
Q. Which of the following operators is the correct option for power(ab)?
1. a ^ b
2. a**b
3. a ^ ^ b
4. a ^ * b
Answer: (b) a**b
Explanation: The power operator in python is a**b, i.e., 2**3=8.
Q. Which of the following precedence order is correct in Python?
1. Parentheses, Exponential, Multiplication, Division, Addition, Subtraction
2. Multiplication, Division, Addition, Subtraction, Parentheses, Exponential
3. Division, Multiplication, Addition, Subtraction, Parentheses, Exponential
4. Exponential, Parentheses, Multiplication, Division, Addition, Subtraction
Answer: (a) Parentheses, Exponential, Multiplication, Division, Addition, Subtraction
Explanation: PEMDAS (similar to BODMAS).
Q. Which one of the following has the same precedence level?
1. Division, Power, Multiplication, Addition and Subtraction
2. Division and Multiplication
3. Subtraction and Division
4. Power and Division
Answer: (b) Division and Multiplication
Explanation: None
Q.Which of the following functions is a built-in function in python language?
1. val()
2. print()
3. print()
4. None of these
Answer: (b) print()
Q. Study the following program:
x = 1
while True:
if x % 5 = = 0:
break
print(x)
x + = 1
What will be the output of this code?
1. error
2. 2 1
3. 0 3 1
4. None of these
Answer: (a) error
Explanation: Syntax error, there should not be a space between + and =.
Q. Study the following statement:
>>>"a"+"bc"
What will be the output of this statement?
1. a+bc
2. abc
3. a bc
4. a
Answer: (b) abc
Explanation: In Python, the "+" operator acts as a concatenation operator between two
strings.
Q. Study the following program:
i = 1:
while True:
if i%3 == 0:
break
print(i)
Which of the following is the correct output of this program?
1. 1 2 3
2. 3 2 1
3. 1 2
4. Invalid syntax
Answer: (d) Invalid syntax
Explanation: Invalid syntax, because this declaration (i = 1:) is wrong.
Q. Study the following program:
a = 1
while True:
if a % 7 = = 0:
break
print(a)
a += 1
Which of the following is correct output of this program?
1. 1 2 3 4 5
2. 1 2 3 4 5 6
3. 1 2 3 4 5 6 7
4. Invalid syntax
Answer: (b) 1 2 3 4 5 6
Explanation: None
Q. Study the following program:
i = 0
while i < 5:
print(i)
i += 1
if i == 3:
break
else:
print(0)
What will be the output of this statement?
1. 1 2 3
2. 0 1 2 3
3. 0 1 2
4. 3 2 1
Answer: (c) 0 1 2
Explanation: None
Q. Study the following program:
i = 0
while i < 3:
print(i)
i += 1
else:
print(0)
What will be the output of this statement?
1. 0 1
2. 0 1 2
3. 0 1 2 0
4. 0 1 2 3
Answer: (c) 0 1 2 0
Explanation: None
Q. Study the following program:
z = "xyz"
j = "j"
while j in z:
print(j, end=" ")
What will be the output of this statement?
1. xyz
2. No output
3. x y z
4. j j j j j j j..
Answer: (b) No output
Explanation: "j" is not in "xyz".
Q. Study the following program:
x = 'pqrs'
for i in range(len(x)):
x[i].upper()
print (x)
Which of the following is the correct output of this program?
1. PQRS
2. pqrs
3. qrs
4. None of these
Answer: (b) pqrs
Explanation: None
Q. Study the following program:
d = {0: 'a', 1: 'b', 2: 'c'}
for i in d:
print(i)
What will be the output of this statement?
1. a b c
2. 0 1 2
3. 0 a 1 b 2 c
4. None of these above
Answer: (b) 0 1 2
Explanation: None
Q. Study the following program:
d = {0, 1, 2}
for x in d:
print(x)
What will be the output of this statement?
1. {0, 1, 2} {0, 1, 2} {0, 1, 2}
2. 0 1 2
3. Syntax_Error
4. None of these above
Q. Which of the following option is not a core data type in the python language?
5. Dictionary
6. Lists
7. Class
8. All of the above
Answer: (c) Class
Explanation: Class is not a core data type because it is a user-defined data type.