python

Python Multiple Choice Questions(MCQ) and Answers

1. Which of the following is a Python tuple?

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

Answer: b
Explanation: Tuples are represented with round brackets

2. What is the output of this expression, 31*3?

a) 3
b) 9
c) 27
d) 1

Answer: a
Explanation: First this will solve 1**3 because exponential has higher precedence than multiplication, so 1**3 = 1 and 3*1 = 3. Final answer will be 3.

3. Which of the following words cannot be a variable in python language?

a) _val

b) try

c) try

d) val

Answer: b
Explanation: “try” is a keyword.

4. Is Python case sensitive when dealing with identifiers?

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

Answer: a
Explanation: Case sensitive is always significant.

5. What is the type of inf?

a) Integer
b) Boolean
c) Float
d) Complex

Answer: c
Explanation: Infinity(inf) is a special case of floating point numbers. It can be obtained by float(‘inf’).

6. Which one of these is floor division?

a) /
b) //
c) %
d) None of the mentioned

Answer: b
Explanation: When both of the operands are integer then python chops out the fraction part and gives you the round off value, to get the accurate answer use floor division.

7. What is the maximum possible length of an identifier?

a) 26
b) 12
c) 100
d) None of these above

Answer: d
Explanation: The maximum possible length of an identifier is not defined in the python language. It can be of any number.

8. What will be the output of the following Python code?

i = 1
while True:
    if i%3 == 0:
        break
    print(i)
    i + = 1

a) 1 2
b) 1 2 3
c) error
d) none of the mentioned

Answer: c
Explanation: SyntaxError, there shouldn’t be a space between + and = in +=.

9. What does 3 ^ 4 evaluate to?

a) 7
b) 0.75
c) 12
d) 81

Answer: a
Explanation: ^ is the Binary XOR operator.

10. What is the value of the following expression?

float(22//3+3/3)

a) 8
b) 8.0
c) 8.3
d) 8.33

Answer: b
Explanation: The expression shown above is evaluated as: float( 7+1) = float(8) = 8.0. Hence the result of this expression is 8.0.

More Reading

Post navigation

Leave a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *