本文主要是介绍Python里面的[::-1]和[::2]是什么意思,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Python里面的[::-1]和[::2]是什么意思
来源:
https://docs.python.org/2.3/whatsnew/section-slices.html
L = range(10)L[::2][0, 2, 4, 6, 8]
L[::-1][9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
s='abcd'
s[::2]
'ac'
s[::-1]
'dcba'
a[::-1] # all items in the array, reversed
a[1::-1] # the first two items, reversed
a[:-3:-1] # the last two items, reversed
a[-3::-1] # everything except the last two items, reversed
这篇关于Python里面的[::-1]和[::2]是什么意思的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!