print(z)
z = complex(1)
print(z)
z = complex()
print(z)
z = complex('5-9j')
print(z)
Run the program, the result is:
(2-3j)
(1 + 0j)
0j
(5-9j)
Example 2: Complex numbers do not use complex () function
In Python, you can create a complex number without using the complex () function .
To do that, you must put 'j' or 'J' after some to Python identity.
a = 2+3j
print('a =',a)
b = -2j
print('b =',b)
c = 0j
print('c =',c)
The output returned is:
a = (2+3j)
b = (-0-2j)
c = 0j
See more:
Previous lesson: classmethod () function in Python
Next article: compile () function in Python