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

Answer:

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) **

Answer:

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

Answer:

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

Answer:

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

Answer:

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

Answer:

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

Answer:

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()

Answer:

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

Answer:

b) Infinity

Explanation:

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

10. How is scientific notation represented in Python for the number 0.000123?

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

Answer:

a) 123e-6

Explanation:

Scientific notation in Python is represented using an 'e' or 'E' followed by the power of ten. 0.000123 is equivalent to 123e-6.


Comments