Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '16,': 0.03; 'subject:Python': 0.06; '*is*': 0.09; '[1,': 0.09; 'received:209.85.219': 0.09; 'python': 0.11; '-1,': 0.16; 'reversing': 0.16; 'slice.': 0.16; 'slicing:': 0.16; 'subject:questions': 0.16; 'index': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'wed,': 0.18; 'all,': 0.19; 'example': 0.22; 'programming': 0.22; 'coding': 0.22; 'email addr:gmail.com>': 0.22; 'to:name :python-list@python.org': 0.22; '>': 0.26; 'header:In-Reply- To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; '(usually': 0.31; '>>>>': 0.31; 'url:python': 0.33; 'received:209.85': 0.35; 'something': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'url:listinfo': 0.36; 'url:org': 0.36; 'list': 0.37; 'received:209': 0.37; 'step': 0.37; 'skip:& 10': 0.38; 'to:addr:python-list': 0.38; 'that,': 0.38; 'skip:& 20': 0.39; 'does': 0.39; 'subject:': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'url:mail': 0.40; 'url:3': 0.61; 'first': 0.61; 'taking': 0.65; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:content-type; bh=2rGmpqXnrofLYDRXWtEuDYI7cWrxK/ininVd7zHeJ/I=; b=icAyityYckWmFQQG21Z2EnA4ulPs5YlcJce3z4uR7msj9S0D+20IBoQb1u4qiNx4HI tfBEfj1lQJ3SKICMg3TnfvweOyCrKRkMgl7eRZlW2h+NIUQTCQvWlZA3AhL2qHmOumWo vZ0bE/e6wcJEw7+5g1cm/ZCrkK8i/nzivLFfF4Vv5JksiF6e5yIHFyp3NxqSSrrHs1/u 3qmwBdvQjg3s6ABvx4lfSKy683/ihij0phoIB74rGnp1fhu0V8RJUzperFJKqUxz3wsq ubJGp6N6K1vJpMNA35IU+t3TuhctID4LkmdW10e4PEd6F7dxvlQ1I+r/iR33fL8vjoEc ARDg== X-Received: by 10.182.156.103 with SMTP id wd7mr978911obb.33.1366126451668; Tue, 16 Apr 2013 08:34:11 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Matt Jones Date: Tue, 16 Apr 2013 10:33:51 -0500 Subject: Re: Newbie questions on Python To: "python-list@python.org" Content-Type: multipart/alternative; boundary=f46d0444e835df0eb704da7c19b5 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 96 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1366126460 news.xs4all.nl 2580 [2001:888:2000:d::a6]:49740 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:43674 --f46d0444e835df0eb704da7c19b5 Content-Type: text/plain; charset=ISO-8859-1 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 wrote: > On Wed, Apr 17, 2013 at 1:20 AM, 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 > --f46d0444e835df0eb704da7c19b5 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
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 i= ndex 2 (third element).

Matt Jones

On Tue, Apr 16, 2013 at 10:30 AM, Chris = Angelico <rosuav@gmail.com> wrote:
On Wed, Apr 17, 2013 at 1:20 AM, =A0<idkfaidkfaidkfa@gmail.com> wrote:
> Hi all,
> i'm programming in python for the first time (usually i use C as p= rogramming language). I don't understand these results:
>
>>>> a=3D[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 subj= ect:

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

--f46d0444e835df0eb704da7c19b5--