Python Numeric Data Types - Practice Questions with Answers
Q1. Type Check
a=5
b = 3.0
c = 2 + 1j
print(type(a)) # int
print(type(b)) # float
print(type(c)) # complex
Q2. Conversion Practice
x = 7.9
y = int(x)
print(y) # Output: 7
Explanation: Decimal part is removed, not rounded.
Q3. Identify Data Types
value1 = 100 # int
value2 = 0.0 # float
value3 = -3.14 # float
value4 = 7 + 5j # complex
Q4. Expression Result
result = 10 + 5.5
print(result) # 15.5
print(type(result)) # float
Q5. Complex Number Output
z = complex(3, 4)
print(z) # (3+4j)
Python Numeric Data Types - Practice Questions with Answers
Q6. True or False
print(isinstance(10.0, int)) # False
print(isinstance(10, int)) # True
Q7. Fill in the Blanks
a = int(10.5) # 10
b = float(4) # 4.0
c = complex(5) # (5+0j)
Q8. Error or Not?
a = 5 + "5" # Error Error
Correct: a = 5 + int("5") # Correct Output: 10
Q9. Arithmetic with Mixed Types
a=5
b = 2.5
c=a*b
print(c) # 12.5
print(type(c)) # float
Q10. Complex Math
x = 2 + 3j
y = 1 + 4j
z=x+y
print(z) # (3+7j)