range(start, stop, step)
1 l = [1,2,3,4,5,6,7,8,9] 2 print l[2:] 3 print l[:2] 4 print l[::2] 5 print l[-2:] 6 print l[:-2] 7 print l[::-2]
python2.7,输出如下:
[3, 4, 5, 6, 7, 8, 9] [1, 2] [1, 3, 5, 7, 9] [8, 9] [1, 2, 3, 4, 5, 6, 7] [9, 7, 5, 3, 1]
Posted qianzeng
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关于list的切片相关的知识,希望对你有一定的参考价值。
range(start, stop, step)
1 l = [1,2,3,4,5,6,7,8,9] 2 print l[2:] 3 print l[:2] 4 print l[::2] 5 print l[-2:] 6 print l[:-2] 7 print l[::-2]
python2.7,输出如下:
[3, 4, 5, 6, 7, 8, 9] [1, 2] [1, 3, 5, 7, 9] [8, 9] [1, 2, 3, 4, 5, 6, 7] [9, 7, 5, 3, 1]
以上是关于关于list的切片的主要内容,如果未能解决你的问题,请参考以下文章
springcloud报错-------关于 hystrix 的异常 FallbackDefinitionException:fallback method wasn't found(代码片段