0
a= 6/5j
print(a)

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

jonrsharpe
  • 107,083
  • 22
  • 201
  • 376
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
  • 73,231
  • 20
  • 109
  • 138
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
  • 13,811
  • 2
  • 31
  • 45