Check a complex number

EasyIf-Else Programs · 44 of 64

Write a Python program to check whether a value is of complex type.

Advertisement
Input
5+6j, 5
Output
(5+6j) True
5 False

Approach

  1. Use isinstance(value, complex).

Solution

Python
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.

Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More if-else programs

← All 64 If-Else Programs