This set of Python Multiple Choice Questions & Answers (MCQs) focuses on “Numeric Types”.

1. What is the output of print 0.1 + 0.2 == 0.3?

a) True

b) False

c) Machine dependent

d) Error

View Answer

Explanation: Neither of 0.1, 0.2 and 0.3 can be represented accurately in binary. The round off errors from 0.1 and 0.2 accumulate and hence there is a difference of 5.5511e-17 between (0.1 + 0.2) and 0.3.

2. Which of the following is not a complex number?

a) k = 2 + 3j

b) k = complex(2, 3)

c) k = 2 + 3l

d) k = 2 + 3J

View Answer

Explanation: l (or L) stands for long.

3. What is the type of inf?

a) Boolean

b) Integer

c) Float

d) Complex

View Answer

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

4. What does ~4 evaluate to?

a) -5

b) -4

c) -3

d) +3

View Answer

Explanation: ~x is equivalent to -(x+1).

5. What does ~~~~~~5 evaluate to?

a) +5

b) -11

c) +11

d) -5

View Answer

Explanation: ~x is equivalent to -(x+1).

6. Which of the following is incorrect?

a) x = 0b101

b) x = 0x4f5

c) x = 19023

d) x = 03964

View Answer

Explanation: Numbers starting with a 0 are octal numbers but 9 isn’t allowed in octal numbers.

7. What is the result of cmp(3, 1)?

a) 1

b) 0

c) True

d) False

View Answer

Explanation: cmp(x, y) returns 1 if x > y, 0 if x == y and -1 if x < y.

8. Which of the following is incorrect?

a) float(‘inf’)

b) float(‘nan’)

c) float(’56’+’78’)

d) float(’12+34′)

View Answer

Explanation: ‘+’ cannot be converted to a float.

9. What is the result of round(0.5) – round(-0.5)?

a) 1.0

b) 2.0

c) 0.0

d) None of the mentioned

View Answer

Explanation: Python rounds off numbers away from 0 when the number to be rounded off is exactly halfway through. round(0.5) is 1 and round(-0.5) is -1.

10. What does 3 ^ 4 evaluate to?

a) 81

b) 12

c) 0.75

d) 7

View Answer

Explanation: ^ is the Binary XOR operator.

**Sanfoundry Global Education & Learning Series – Python.**

To practice all areas of Python, __here is complete set of 1000+ Multiple Choice Questions and Answers__.