简体   繁体   中英

Why is imaginary part of complex number negative when it is divided?

a= 6/5j
print(a)

It prints -1.2j . Why it is a negative value in Python?

More of a math question, but the answer is

6/(5j) = 6j/(5jj) = 6j/(-5) = -1.2j

In general, 1/j = j/(jj) = -j

In python, a complex literal is (floatnumber | digitpart) ("j" | "J") with an optional real part in front of it. Therefore in

6/5j

5j is interpreted as a complex literal, which makes the calculation result correct (see other answers). To have a "lonely" j in your calculation, you always need to add a 1 in front of it:

6/5*1j

This does differ from how eg wolframalpha would handle the same input.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM