Assignment to slice

Mel Wilson mwilson at the-wire.com
Thu Jan 22 10:16:59 EST 2004


In article <20040121185145.C648.JCARLSON at uci.edu>,
Josiah Carlson <jcarlson at uci.edu> wrote:
>
>All 'different' language features are 'unusual' until people get used to
>them.  While you are currently saying, "I can't believe people don't
>think this is strange", the rest of us got over it, and may even be
>using the feature to get the job done.

   I really do rely on asking Python "What's in positions
100 to 103 of this string?" and have Python reply "Nothing".
It never occurred to me to try to assign to non-existent
slices.. but I'll accept the present behaviour if it means
Python stays simple and consistent.

   The rule for `a=[]; a[4:5]=[1,2,3,4]` seems to result in
concatenating a[:4], then [1,2,3,4], then a[5:].  That is:
nothing, followed by 1, 2, 3, and 4, then more nothing.

>Hell, I think that Perl variables are f-ing weird.  In the dozen
>languages I've learned over the years, Perl is the only one where you
>have to say hey, you this variable I'm accessing now, it is a scalar,
>not a string.  What the hell is that?  On the other hand, Perl users
>have gotten used to it, and don't think it is strange.

   This seems to have emerged from a Perl tendency to
implement values as strings wherever possible.  You're
saying "Use the stringness of this variable, rather than,
say, its intness."  Weak typing, but it's what lets Perl
automatically fill in missing array values with some
assurance that it won't all go kaboom in the next statement.

        Regards.        Mel.



More information about the Python-list mailing list