Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > mystery string code - help!

Reply
Thread Tools

mystery string code - help!

 
 
Uncle Ben
Guest
Posts: n/a
 
      04-20-2011
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
 
Reply With Quote
 
 
 
 
Dan M
Guest
Posts: n/a
 
      04-20-2011
> 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 at
http://docs.python.org/release/2.3.5...on-slices.html

Dan
 
Reply With Quote
 
 
 
 
Uncle Ben
Guest
Posts: n/a
 
      04-21-2011
On Apr 20, 1:01*pm, Dan M <catd...@gmail.com> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: string interpolation mystery in Python 2.6 Alan G Isaac Python 4 09-12-2009 11:26 PM
string find mystery Helvin Python 5 09-03-2009 12:17 PM
String escape mystery. Rick DeNatale Ruby 5 11-17-2007 11:14 PM
Mystery String Jonathan Shan C Programming 19 07-27-2006 02:23 AM
Inline code in header files - learned my lesson, but one mystery remains S Austin C++ 1 01-29-2004 08:30 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57