sequence multiplied by -1
Mel
mwilson at the-wire.com
Sun Sep 26 11:31:51 EDT 2010
Grant Edwards wrote:
> On 2010-09-26, Paul Rubin <no.email at nospam.invalid> wrote:
>> Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> writes:
>>> There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam",
>
>> Why would it not be ["spam","spam","spam"] or even "ssspppaaammm"?
>
> Because
>
> 3 * "spam" == "spam" + "spam" + "spam"
>
> Just like
>
> 3 * 6 = 6 + 6 + 6
>
> So now I suppose "+" for string concatenation is a bad thing.
It's awkward for math purists because there's no additive inverse .. hence
the original poster's idea to simply create one out of the blue. For string
lengths and list lengths we're stuck with non-negative integers, and no hope
of general-purpose subtraction.
I wouldn't change it. As an idiom, ' '*20 is just too handy a way to get a
20-blank string to give up.
Mel.
More information about the Python-list
mailing list