Format of complex number in Python

后端 未结 4 1626
清歌不尽
清歌不尽 2020-12-18 19:13

I am wondering about the way Python (3.3.0) prints complex numbers. I am looking for an explanation, not a way to change the print.

Example:

>>         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-18 20:01

    As far as the first question is concerned: if it just printed 0 it would be mathematically correct, but you wouldn't know you were dealing with a complex object vs an int. As long as you don't specify .real you will always get a J component.

    I'm not sure why you would ever get -0; it's not technically incorrect (-1 * 0 = 0) but it's syntactically odd.

    As far as the rest goes, it's strange that it isn't consistent, however none are technically correct, just an artifact of the implementation.

提交回复
热议问题