Why and how are -1j
and 0 - 1j
turned into different strings?
>>> a = -1j
>>> b = 0 - 1j
>>> a
(-0-1j)
>>> b
-1j
They're the same value of the same type:
>>> a == b
True
>>> type(a), type(b), type(a) is type(b)
(<class 'complex'>, <class 'complex'>, True)
But both str
and repr
turn them into different strings:
>>> str(a), str(b)
('(-0-1j)', '-1j')
>>> repr(a), repr(b)
('(-0-1j)', '-1j')
Why and how does that happen?
Note: This is in Python 3.6.4. In Python 2.7.14 they're both turned into '-1j'
.