What does "::" mean?
Rob Williscroft
rtw at freenet.co.uk
Wed Jul 20 17:08:01 EDT 2005
Robert Kern wrote in news:mailman.1954.1121875043.10512.python-
list at python.org in comp.lang.python:
> qwweeeit at yahoo.it wrote:
>> Hi Robert,
>> I didn't succeed in reversing a string with the "full form" you
>> proposed:
>> live[len(live)-1:-1:-1] # where live="live"
>> The result is an empty string.
>> To reverse "live" (in a "full form"), I have to put a char in front of
>> the string and...:
>> ('x'+live)[len(live)+1:0:-1] # --> "evil"
>> Is it due to the Python's version (I still have 2.3.4)?
>
> No, it's because I am stupid. There isn't a full form.
> live[len(live)::-1] is the closest expansion.
>
import sys
live = 'live'
print live[ sys.maxint : : -1 ]
print live[ len(live)-1 : : -1 ]
print live[ len(live)-1 : -len(live)-1 : -1 ]
print live[ len(live)-1 : -sys.maxint : -1 ]
print live[ sys.maxint : -sys.maxint : -1 ]
print live[ -1 : -len(live)-1 : -1 ]
Of course there is only one obvious way to do it, but alas
as I'm not Dutch I can't tell which it is.
Rob.
--
http://www.victim-prime.dsl.pipex.com/
More information about the Python-list
mailing list