Python
python 切片的三个参数
slice[beg:end:step]
若 step > 0, 则表示从左向右进行切片。此时,beg必须小于end才有结果,否则为空。
若 step < 0, 则表示从右向左进行切片。 此时,beg必须大于end才有结果,否则为空。
当step(步长值)小 于0,此时列表切片的默认值为beg=-1,end=-len(slice).
举例:
>>> list_test = ['boduo','xiaoze','canglaoshi','jize','wutenglan']
>>> print (list_test[:])
['boduo', 'xiaoze', 'canglaoshi', 'jize', 'wutenglan']
>>> print (list_test[-5:])
['boduo', 'xiaoze', 'canglaoshi', 'jize', 'wutenglan']
>>> print (list_test[::-1])
['wutenglan', 'jize', 'canglaoshi', 'xiaoze', 'boduo']
>>> print (list_test[-5::-1])
['boduo']
>>>
应用举例:将输入的字符串倒序输出
s=list(input())
s=s[::-1]
print("".join(map(str,s)))