I want to assign an imaginary number to a variable:
import math
a = sqrt(4)j
print(a)
This results in a SyntaxError:
Line 3: SyntaxError: bad input ('j')
I can assign an imaginary number to variable like this:
a = 2j
How do I solve this?
I want to assign an imaginary number to a variable:
import math
a = sqrt(4)j
print(a)
This results in a SyntaxError:
Line 3: SyntaxError: bad input ('j')
I can assign an imaginary number to variable like this:
a = 2j
How do I solve this?
You can simply use complex() to return:
real + imag*1jor convert a string or number to a complex number
>>> a = complex(0,math.sqrt(4))
>>> a
2j
Use the complex function.
>>> complex(0, sqrt(4))
2j