0
a= 6/5j
print(a)

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

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Rooney
  • 19

2 Answers2

4

More of a math question, but the answer is

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

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

timgeb
  • 76,762
  • 20
  • 123
  • 145
4

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 e.g. wolframalpha would handle the same input.

FlyingTeller
  • 17,638
  • 3
  • 38
  • 53