sequence multiplied by -1

Carl Banks pavlovevidence at gmail.com
Fri Oct 1 13:24:11 EDT 2010


On Sep 26, 8:20 am, Grant Edwards <inva... at invalid.invalid> wrote:
> On 2010-09-26, Paul Rubin <no.em... at nospam.invalid> wrote:
>
> > Steven D'Aprano <st... 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.

Yes.  It's not the end of the world, but a separate concatenation
operator would have been better.  Then there's no temptation to
special case a failure of sum(list_of_strings), because it's not a sum
any more.

As for repeat, I can't personally think of a time I ever repeated
anything but a single item, and that only rarely.  It's not useful
enough to deserve its own syntax, and the language wouldn't have
suffered one bit if it had been a method of sequences.


Carl Banks


Carl Banks



More information about the Python-list mailing list