Are complex numbers a supported data-type in Python? If so, how do you use them?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In python, you can put ‘j’ or ‘J’ after a number to make it imaginary, so you can write complex literals easily:
The ‘j’ suffix comes from electrical engineering, where the variable ‘i’ is usually used for current. (Reasoning found here.)
The type of a complex number is
complex, and you can use the type as a constructor if you prefer:A complex number has some built-in accessors:
Several built-in functions support complex numbers:
The standard module
cmathhas more functions that handle complex numbers: