Python Numbers MCQ Questions and Answers

1. What is the output of 5 ** 2 in Python?

a) 25
b) 10
c) 7
d) 2.5

a) 25

Explanation:

The ** operator in Python is used for exponentiation. 5 ** 2 calculates 5 raised to the power of 2, which is 25.

2. Which of the following is used for integer division in Python?

a) /
b) //
c) %
d) **

b) //

Explanation:

The // operator in Python is used for integer (floor) division. It divides and returns the integer part of the quotient.

3. How do you represent a hexadecimal number 1A in Python?

a) 0x1A
b) 1Ax
c) 1A
d) #1A

a) 0x1A

Explanation:

In Python, hexadecimal numbers are represented with a leading 0x or 0X.

4. What is the result of the expression 8 % 3 in Python?

a) 2
b) 2.67
c) 5
d) 1

a) 2

Explanation:

The % operator in Python returns the remainder of the division. 8 divided by 3 leaves a remainder of 2.

5. What data type is the number 5.5 in Python?

a) int
b) float
c) decimal
d) double

b) float

Explanation:

In Python, numbers with a decimal point are considered floating-point numbers.

6. What is the type of the number 3+4j in Python?

a) int
b) float
c) complex
d) str

c) complex

Explanation:

In Python, complex numbers are written in the form a + bj, where a is the real part and b is the imaginary part.

7. What is the result of the expression int(7.8) in Python?

a) 7
b) 8
c) 7.8
d) Error

a) 7

Explanation:

The int() function in Python converts a floating-point number to an integer by truncating the decimal part.

8. Which function in Python is used to generate a range of numbers?

a) range()
b) xrange()
c) numbers()
d) list()

a) range()

Explanation:

The range() function is used to generate a sequence of numbers in Python. xrange() was used in Python 2.

9. What does the expression float('inf') represent in Python?

a) A large integer value
b) Infinity
c) An error
d) Zero

b) Infinity

Explanation:

float('inf') represents positive infinity in Python. It's used to represent a value that is larger than all other values.

a) 123e-6
b) 0.000123e0
c) 1.23e-4
d) 123e-4