[Tutor] What exactly is [::-1]?

wesley chun wescpy at gmail.com
Thu Jul 26 08:28:09 CEST 2007


when you use the 3rd element, it's called the extended slice syntax.
here are a few more examples:

>>> x = 'python programming'
>>> x[::-1]
'gnimmargorp nohtyp'
>>> x[2:12:2]
'to rg'
>>>

ironically, this feature has been available in the interpreter for
many years, but it wasn't until circa 2.3 that it was available via
Python syntax.  it was also odd that i could use the extended slice
syntax with Jython (formerly JPython) 1.1 when it wasn't available in
the standard C Python back in the day.

hope this helps!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
    http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com


More information about the Tutor mailing list