Posted on

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) {}

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]Answer: b
Explanation: Tuples are represented with round brackets[/bg_collapse]

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

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

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]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.[/bg_collapse]

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

a) _val

b) try

c) try

d) val

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]Answer: b
Explanation: “try” is a keyword.[/bg_collapse]

4. Is Python case sensitive when dealing with identifiers?

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

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]Answer: a
Explanation: Case sensitive is always significant.[/bg_collapse]

5. What is the type of inf?

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

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]Answer: c
Explanation: Infinity(inf) is a special case of floating point numbers. It can be obtained by float(‘inf’).[/bg_collapse]

6. Which one of these is floor division?

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

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]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.[/bg_collapse]

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

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

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]Answer: d
Explanation: The maximum possible length of an identifier is not defined in the python language. It can be of any number.[/bg_collapse]

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

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]Answer: c
Explanation: SyntaxError, there shouldn’t be a space between + and = in +=.[/bg_collapse]

9. What does 3 ^ 4 evaluate to?

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

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]Answer: a
Explanation: ^ is the Binary XOR operator.[/bg_collapse]

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

[bg_collapse view=”button-orange” color=”#4a4949″ icon=”eye” expand_text=”Show More” collapse_text=”Show Less” ]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.[/bg_collapse]

Write a comment