Newbie questions on Python

Matt Jones matt.walker.jones at gmail.com
Tue Apr 16 11:33:51 EDT 2013


When slicing: l[start:end:step]

In your example of "a[2::-1]" you are reversing the list by using a step of
-1, then you are slicing at index 2 (third element).

*Matt Jones*


On Tue, Apr 16, 2013 at 10:30 AM, Chris Angelico <rosuav at gmail.com> wrote:

> On Wed, Apr 17, 2013 at 1:20 AM,  <idkfaidkfaidkfa at gmail.com> wrote:
> > Hi all,
> > i'm programming in python for the first time (usually i use C as
> programming language). I don't understand these results:
> >
> >>>> a=[1,2,3,4,5]
> >>>> a[:-1]
> > [1, 2, 3, 4]
> >>>> a[::-1]
> > [5, 4, 3, 2, 1]
> >>>> a[2::-1]
> > [3, 2, 1]
> >
> > what does a[2::-1] means?
>
> That's taking a slice. This page has something to say on the subject:
>
> http://docs.python.org/3.3/tutorial/introduction.html
>
> By the way, regarding your email address: there are no cheat codes in
> Python... either that, or Python *is* a cheat code. :)
>
> ChrisA
> [[ VERY HAPPY CODING ADDED ]]
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130416/74d29f27/attachment.html>


More information about the Python-list mailing list