Python Practice › If-Else Programs › Program 44
Check a complex number
Write a Python program to check whether a value is of complex type.
Input
5+6j, 5
Output
(5+6j) True 5 False
Approach
- Use
isinstance(value, complex).
Solution
for value in [5 + 6j, 5]: print(value, isinstance(value, complex))Output
(5+6j) True 5 False
Line by line
Line 1
j marks the imaginary part in Python.
Learn the concept
New to this topic? Read the lesson, then come back.