码迷,mamicode.com
首页 > 编程语言 > 详细

python中列表切片

时间:2021-04-29 12:03:12      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:列表   size   span   基本用法   nbsp   python   切片   div   用法   

python中列表切片。

1、基本用法

>>> test1
[11, 22, 33, 44, 55, 66, 77, 88, 99, 0]
>>> test1[2:5]
[33, 44, 55]

 

2、

>>> test1
[11, 22, 33, 44, 55, 66, 77, 88, 99, 0]
>>> test1[:3]
[11, 22, 33]
>>> test1
[11, 22, 33, 44, 55, 66, 77, 88, 99, 0]
>>> test1[7:]
[88, 99, 0]
>>> test1
[11, 22, 33, 44, 55, 66, 77, 88, 99, 0]
>>> test1[:]
[11, 22, 33, 44, 55, 66, 77, 88, 99, 0]

 

3、

>>> test1
[11, 22, 33, 44, 55, 66, 77, 88, 99, 0]
>>> test2[-5:-2]
[66, 77, 88]
>>> test1
[11, 22, 33, 44, 55, 66, 77, 88, 99, 0]
>>> test1[-5:]
[66, 77, 88, 99, 0]

 

4、

>>> test1
[11, 22, 33, 44, 55, 66, 77, 88, 99, 0]
>>> test1[0:10:2]
[11, 33, 55, 77, 99]
>>> test1[::2]
[11, 33, 55, 77, 99]
>>> test1[::3]
[11, 44, 77, 0]

 

5、

>>> test1
[11, 22, 33, 44, 55, 66, 77, 88, 99, 0]
>>> test1[::-1]
[0, 99, 88, 77, 66, 55, 44, 33, 22, 11]
>>> test1
[11, 22, 33, 44, 55, 66, 77, 88, 99, 0]
>>> test1[::-2]
[0, 88, 66, 44, 22]

 

6、

>>> test1
[11, 22, 33, 44, 55, 66, 77, 88, 99, 0]
>>> test1[-1:-8:-2]
[0, 88, 66, 44]

 

python中列表切片

标签:列表   size   span   基本用法   nbsp   python   切片   div   用法   

原文地址:https://www.cnblogs.com/liujiaxin2018/p/14715627.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!