mystery string code - help!

Discussion in 'Python' started by Uncle Ben, Apr 20, 2011.

  1. Uncle Ben

    Uncle Ben Guest

    I found this in one of the online cookbooks:

    #Raghunath Reddy Peesari 6 years, 3 months ago # | flag
    #There is more simple way. ###

    a = 'abcdefghi'
    a = a[::-1]

    print a

    >>> 'ihgfedcba'


    As a newbie Pythoner, I understand [] -1]
    but would some tell me how '::' does its magic?

    Uncle Ben
     
    Uncle Ben, Apr 20, 2011
    #1
    1. Advertising

  2. Uncle Ben

    Dan M Guest

    Dan M, Apr 20, 2011
    #2
    1. Advertising

  3. Uncle Ben

    Uncle Ben Guest

    On Apr 20, 1:01 pm, Dan M <> wrote:
    > > As a newbie Pythoner, I understand [] -1] but would some tell me how
    > > '::' does its magic?

    >
    > > Uncle Ben

    >
    > The -1 is the "stride" or "step" argument. It's described athttp://docs.python.org/release/2.3.5/whatsnew/section-slices.html
    >
    > Dan


    Very helpful!

    Ben
     
    Uncle Ben, Apr 21, 2011
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. S Austin
    Replies:
    1
    Views:
    344
    Victor Bazarov
    Jan 29, 2004
  2. Jonathan Shan

    Mystery String

    Jonathan Shan, Jul 25, 2006, in forum: C Programming
    Replies:
    19
    Views:
    602
    Eric Sosman
    Jul 27, 2006
  3. Helvin

    string find mystery

    Helvin, Sep 3, 2009, in forum: Python
    Replies:
    5
    Views:
    358
    Hendrik van Rooyen
    Sep 3, 2009
  4. Alan G Isaac
    Replies:
    4
    Views:
    435
    Alan G Isaac
    Sep 13, 2009
  5. Rick DeNatale

    String escape mystery.

    Rick DeNatale, Nov 17, 2007, in forum: Ruby
    Replies:
    5
    Views:
    126
    Wolfgang Nádasi-Donner
    Nov 17, 2007
Loading...

Share This Page