[Tutor] (no subject)
Wed, 30 Aug 2000 19:19:51 -0700 (PDT)
> Here is a question in the python munual 3.1.3.
> The example said:
> a = ['spam', 'eggs', 100, 1234];
> a='spam',a='eggs',a=100 and a=1234;
> It then said:
> I think it's a error assignment.
> 'Cause I believe a[0:2]=['spam','eggs',100];
When you try something like:
this will take a and a. It's a little weird at first, but it
actually simplifies program logic that works with arrays. You'll need to
write a few programs, though, before it makes sense.
The '' operator will make a slice starting at the left element, all the
way up to, but not including, the right element.
is the same thing as a[0:2], and can be read as "take the first 2 elements
If you're curious, the range() function has similar behavior: