really silly nit: why 3+5j instead of 3+5i?

Thomas Wouters thomas at xs4all.net
Sun May 14 17:36:42 CEST 2000


On Sun, May 14, 2000 at 01:06:37PM +0100, Tim Northover wrote:
> jimn at minusen.force9.co.uk writes:
> > As I see it, the problem would come when converting a complex number
> > to a string - which representation should it use? Is it not preferable 
> > to use the same representation for display as is used for literals?

> I'm quite a newbie (read very), but it seems that there is a precedent
> in strings which can be either ' or " but ' is used for printing. Is 
> this now considered to have been a mistake or a special case?

A mistake ? Absolutely not. I *like* the fact that "" and '' behave exactly
alike, with the only difference being which type of quote you have to
escape. As for the representation, dont think it just uses single quotes --
the interpreter is being very cleaver about it. It prefers single quotes,
but it will happily use double ones to avoid unecessary escaping:

>>> "do not"
'do not'
>>> 'do not'
'do not'
>>> "don't"
"don't"
>>> 'don\'t'
"don't"
>>> 'I said, "Don\'t"'
'I said, "Don\'t"'
>>> "I said, \"Don't\"" 
'I said, "Don\'t"'

It doesn't count the number of quotes, though, so if both quotes are used,
escaped, in the string, it will default to single quotes. I dont
particularly see the same need with complex numbers, myself ;-P

floats-are-complex-enough-for-me-ly y'rs,
-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list