对list进行切片

取一个list的部分元素是非常常见的操作。比如,一个list如下:

>>> L = ['Adam', 'Lisa', 'Bart', 'Paul']

取前3个元素,应该怎么做?

笨办法:

>>> [L[0], L[1], L[2]]
['Adam', 'Lisa', 'Bart']

之所以是笨办法是因为扩展一下,取前N个元素就没辙了。

取前N个元素,也就是索引为0-(N-1)的元素,可以用循环:

>>> r = []
>>> n = 3
>>> for i in range(n):
... r.append(L[i])
...
>>> r
['Adam', 'Lisa', 'Bart']

对这种经常取指定索引范围的操作,用循环十分繁琐,因此,Python提供了切片(Slice)操作符,能大大简化这种操作。

对应上面的问题,取前3个元素,用一行代码就可以完成切片:

>>> L[0:3]
['Adam', 'Lisa', 'Bart']

L[0:3]表示,从索引0开始取,直到索引3为止,但不包括索引3。即索引0,1,2,正好是3个元素。

如果第一个索引是0,还可以省略:

>>> L[:3]
['Adam', 'Lisa', 'Bart']

也可以从索引1开始,取出2个元素出来:

>>> L[1:3]
['Lisa', 'Bart']

只用一个 : ,表示从头到尾:

>>> L[:]
['Adam', 'Lisa', 'Bart', 'Paul']

因此,L[:]实际上复制出了一个新list。

切片操作还可以指定第三个参数:

>>> L[::2]
['Adam', 'Bart']

第三个参数表示每N个取一个,上面的 L[::2] 会每两个元素取出一个来,也就是隔一个取一个。

把list换成tuple,切片操作完全相同,只是切片的结果也变成了tuple。

任务

range()函数可以创建一个数列:

>>> range(1, 101)
[1, 2, 3, ..., 100]

请利用切片,取出:

1. 前10个数;
2. 3的倍数;
3. 不大于50的5的倍数。

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA1sAAACpCAIAAABS7LDdAAAdS0lEQVR4nO2dW2wc133G9zU3J83FkK2saMZRIrd0bMfZmIgcMVrRlnhz1MiULckmldAmWrRVCVE2FBEpswa0D20UtSYNUYpQNC4RoY1phkoatyEth2gpEG2AoCjSAgW6D+lbCjRNAj2fPuxtZmfO7Fz+Z87s8vfh98Cd3fnOf2d3z/l45pb78D17AAAAACA5d+++7+CRsbHxE0+MPrXvMw/39u3dtWfPXR/8wHs/8P53vffdg08NffNbV/76e2+WFxe+PDN76S+X/uXff/pf//2f33977dDYyLve9578/b19j326/9AXjp54bmz8xBcOj35k933pVJ6zvu0AAAAAuoZ78vc/Mfa7Y+MnBkfH7tu394N3f/iu33r/u9733p69H//29777s8q//fif//Eftn905cbf/N3mW//6Hz+t/Pxn//O/P59/9eJHdt+766P3fn50ePTpZ8bGTzwxdvSe/P2plU0iBAAAAJBkz8f3PfnUsbHxE08+dfRjn/jYh3bd/e673vfJhx5+5S8u/dV3v/ODH//9m2+/9a2//faNH9zc/Mk/vf2T9e+/86PjL0zf98lP9BUeHh0/MTZ+4smxL+25f1+aNZMIAQAAAIS5Z8/9Xzg8MjZ+Ymz8xOPFQ7t2737P++/a+9ADR5555o/+5Pwffq305T/+g997+fyfXX3t63/+zSPPHvvkIw8dHB6qvn7gyeFde9KbHaxCIgQAAACQ5+57ex767OeGv/RMNecdGh7tP3DowUc/8+BnCz377v/Qrrt/59OfenT/4weHR5946mj1NaPHnnn4sf137+5Jv1oSIQAAAIAp7u35+GMHiqPHarlQx+ixZx47cGj3fXtt1UkiBAAAADDLro9+7IGHHu0fOHTwyNiRLz49+vSzo08/e+SLTx88MvrYgUMPPPTornyv3QpJhAAAAAA7HRIhAAAAwE6HRAgAAACw0yERAgAAAOx0SIQAAAAAOx0SIQAAAMBOh0QIAAAAsNMhEQIAAADsdEiEAAAAADsdEiEAAADATodECAAAALDTIRECAAAA7HRIhAAAAAA7HRIhAAAAwE6HRAgAAACw08n98pe//D+HfvWrX/3617/+xS9+ke/pBSlyCCGkkUIIoQyIREgiRAjZlO1RACGElCIRkggRQnZlexRACCGlSIQkQoSQXdkeBRBCSCkSIYkQIWRXtkcBhBBSikRIIkQI2ZXtUQAhhJRSKnfnzp3f/OY3JEISIULIimyPAgghpJRSuQcffNAZCkmEJEKEUJqyPQoghJBSSuUKhcKpU6caoZBESCJECKUp26MAQggppVTuq1/96je+8Y1yuVwNhSRCEiFCK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F6Oenqkv99zCLpJPFa5WA5AFbI8CCCGklNFEGCkF2t1rbD4R9pVLk8szIyEToe8tSaZnGkHQ/y52IX0akAgBsoDtUQAhhJTqhERYvR7hyYu1u9Itn6nfIHj/xPL1iYH9E8vVu881Il1jid99jVt9mi/2u1GeP9ET4eDzxyul4uCQNxH63MVOk+T6l503Ry4UN133Sg7v04RECJAFbI8CCCGkVKckwpuLtYtU759YbuwLroW56sPCueuOsJj3uetx1ccRBB3Pmp0jbKS3JIlwaKR5Q+TqDuiFyeWhxgtIhACdiu1RACGElErpOMK1rx9OOkfYeHjyojPVNY8UbC6v4psImz7Dl5xHGRpNhNMz9WP4fBKhj4nr+L/G8YLVdWtZ8Hi50FcuORNhaB8HJEKALGB7FEAIIaXSOdf4K0vRQqG7uwxMhPo9vFlJhI4UGDIROmkeOzg0UqllwepT7ROhv48DEiFAFrA9CiCEkFIpXX3mhStb21e+IpIIC+euL14a7+nNd0gibJ4d7GB5KPTVZxo7iwvFTedu4tbjCEP7OCARAmQB26MAQggplUoiHPna2u2tpWmRvcbjM80zPwQToXsHdDviXX2mJ+xxhA5c5xQ75/mmZ1rONY7g04BECJAFbI8CCCGklLFEOPK1tZgXI/RNhL4nAmsSofv1zVWCEqFrrTDnGjsutejMYRKJsK9c0l1E0PFUa7yL5FODRAiQBWyPAgghpFQn3LOk5TjCTNMmETrIwl3sSIQAWcD2KIAQQkqRCGUhEQJAVGyPAgghpBSJUBbuawwAUbE9CiCEkFKdkAi7kyzMEQJAFrA9CiCEkFIBiXDvvj5bWO+gAQBSw/YogBBCSpEIAQDsYnsUQAghpUiEAAB2sT0KIISQUiRCAAC72B4FEEJIKRIhAIBdbI8CCCGkFIkQAMAutkcBhBBSikQIAGAX26MAQggpRSIEALCL7VEAIYSUIhECANjF9iiAEEJKkQgBAOxiexRACCGlSIQAAHaxPQoghJBSJEIAALvYHgUQQkgppf4fT6spw41ySXcAAAAASUVORK5CYII=" alt="" />

倒序切片

对于list,既然Python支持L[-1]取倒数第一个元素,那么它同样支持倒数切片,试试:

>>> L = ['Adam', 'Lisa', 'Bart', 'Paul']

>>> L[-2:]
['Bart', 'Paul'] >>> L[:-2]
['Adam', 'Lisa'] >>> L[-3:-1]
['Lisa', 'Bart'] >>> L[-4:-1:2]
['Adam', 'Bart']

记住倒数第一个元素的索引是-1。倒序切片包含起始索引,不包含结束索引。

任务

利用倒序切片对 1 - 100 的数列取出:

* 最后10个数;

* 最后10个5的倍数。

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA10AAACKCAIAAADeyrcCAAAYt0lEQVR4nO2dfXAU533H9a8NflcwAk5CgJAw4k1wIN4k9IJBOp2sgE5CyEjmTbVbF6sIYxlKsGjRTGxjYktUQHDHsdUwdQwEkprWknFoAqNp02baTNK0k146cTOeunVrw/C3+sfey+7dPXtvz+6zp/185jMMt3f3e5473e3vO7u3u3n5BYX5BYVru070d9Vp/w9Zta//2L61BUWGhTEPiHlKyq7tiq1c2tzXf+yEiTurxDOJWN763LF9a6v2mZcKF6zbeayvsTx52dLmvv7wI9d2hWaytkurE6lQ0XggXDzTtwUREaekWo8LN7KKxgMn+g+0lmp9sGpf/7ETzzVXKJ+kwfLW55J30pR6qDOmqnLyZUsr/IGOWp9/S3vr13d3+zrbK7fWLl69qqR80dLV3vWNm5dXehvbd/xe/+EP//aT4G9+VVG5ZOSd87/+3b/+0Z+8st7vm10yd13Dk7sPvrBq44b5i0vnPbGo3FuxyLviqR27/IGO0qWSPzl5sR/QsGu7EizUW9rcJzUA6XJVnOl+YZKmzDRnXrfzWOTdqNuZIK3qJ28aphER0X3mWC5MI2k5IBo6Phc+7in2bW/3BzqWrl61eOWK0hXlZSuXL6v0Lt9Yuaa+vrJm04aW5l0vPP+NN9945+p7//U/v3v/2vu//PU//+Y/fzVy8Z3m3XtWbqz07ezY5PcVFBUUlS5csXFtY+c2X2eXP9Dh29b2+JxiubPNM34c9aFH8Jbp/gApbcNLx/BGuKxCYdwLyTIUGgomeMn6zZOmSRoREd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cHAHAj5EJERCequjsAgBshFyIiOlHV3QEA3Mj/A3xfszo+zSgdAAAAAElFTkSuQmCC" alt="" />

对字符串切片

字符串 'xxx'和 Unicode字符串 u'xxx'也可以看成是一种list,每个元素就是一个字符。因此,字符串也可以用切片操作,只是操作结果仍是字符串:

>>> 'ABCDEFG'[:3]
'ABC'
>>> 'ABCDEFG'[-3:]
'EFG'
>>> 'ABCDEFG'[::2]
'ACEG'

在很多编程语言中,针对字符串提供了很多各种截取函数,其实目的就是对字符串切片。Python没有针对字符串的截取函数,只需要切片一个操作就可以完成,非常简单。

任务

字符串有个方法 upper() 可以把字符变成大写字母:

>>> 'abc'.upper()
'ABC'

但它会把所有字母都变成大写。请设计一个函数,它接受一个字符串,然后返回一个仅首字母变成大写的字符串。

提示:利用切片操作简化字符串操作。

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAkAAAAC3CAIAAAB18HbpAAAXnElEQVR4nO2dUWsUy7qG/SMh5GKDbMQ7YbOyjBg8ZBtZN4IeCHH0LEU8NyokQnDYZCvo4hzIvogTjCJeiVeGkIDsi8QD6yIhv2L+Ss5FT3dXdVf1dE9XzTfz+bw8FzM93TWdTnxfq7q6vgszs3PQngsIIeTROYqjC+LWrwPpfyAIocmVtM+rFQFGgCGE4kra59WKACPAEEJxJe3zakWAEWAIobiS9nm1IsAIMIRQXEn7vFoRYAQYQiiupH1erQgwAgwhFFfSPq9WBBgBhhCKK2mfVysCjABDCMWVtM+rFQFGgCGE4kra59WKACPAEEJxJe3zakWAEWAIobgKY9Z2a3Ua9+0T9sQERYARYAihuArm13ZTNVv27RbwxKREgBFgCKG4CubXBJgtAowAQwjFVTC/JsBsEWAEGEIoroL5tT/AKr7OdwLO7TFOO54IMAIMIRRXwfza0/KFyp6Z7wTK22seODkiwAgwhFBcBfNrT8BUf6PvBMrbax44OSLACDCEUFwF82t/gNU/qmK7r/2JVawAWzs+Pz9+UXfP8/Pz/sdl6RAiwBBCMRTMrwkwW/IBNjM7N7N2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aicoS1KpRdrn1WrkAHvUO9vvbr5P3XO/u9QqwChoSUHL/DfrKSZp9l2M15fT1EmPLa0uX6udldtJI3e3kpTKOl5W+zMrt7OHnT3nk2Znvih+zcrO07LaFjRG2ufVqk2AGSvQByynQkHLIhS0TLALVObVUgpDfNZurgDztJOu9pvGZ7aYva993/kUQtTerRIKY2pF2ufVql0PbMn3NlyATXk9MApaOn6EGjgKWhaqUBaH+LJjhwWYr52mAeY9H28PcjgUxlSKtM+rVasemDGDI1yAUdDSdSwFLf1dGTtg7DqWw3tgGS17YOZf5qgBxjwOrUj7vFq1msRxcrB54+Klv1y8dGNzP3vdMsAoaElBS+u37CxoaWEFTGEf5+ry7nbqBZjvvpfvnBvBPTCtSPu8WrV5DsyoadkkvZwBRkHLvCkKWvoKWhY+sidxlKcaFj/NP3IdUhlgnvbdH40aYMxCVIu0z6vVJKzEQTkVWaa9oGXg57SkYPxQMdI+r1YEGEx7QUsVAcZKHKqR9nm1IsBg2gtaKggw1kJUjrTPq9UkBBgAgGakfV6tCDAAgLhI+7xaEWAAAHGR9nm1IsAAAOIi7fNqRYABAMRF2ufVigADAIiLtM+rFQEGABAXaZ9XKwIMACAu0j6vVgQYAEBcpH1erQgwAIC4SPu8WhFgAABxkfZ5tSLAAADiIu3zakWAAQDERdrn1YoAAwCIi7TPqxUBBgAQF2mfVysCDAAgLtI+r1YEGABAXKR9Xq0IMACAuEj7vFoRYAAAcZH2ebUiwAAA4iLt82pFgAEAxEXa59WKAAMAiIu0z6sVAQYAEBdpn1crAgwAIC7SPq9WBBgAQFykfV6tCDAAgLhI+7xaEWAAAHGR9nm1IsAAAOIi7fNqRYABAMRF2ufVigADAIiLtM+rFQEGABAXaZ9XKwIMACAu0j6vVv8PIxlqh94eerkAAAAASUVORK5CYII=" alt="" />

Python 入门(八)切片的更多相关文章

  1. Python入门篇-基础数据类型之整型(int),字符串(str),字节(bytes),列表(list)和切片(slice)

    Python入门篇-基础数据类型之整型(int),字符串(str),字节(bytes),列表(list)和切片(slice) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Py ...

  2. Python入门基础之函数、切片

    Python之函数 Python不但能非常灵活地定义函数,而且本身内置了很多有用的函数,可以直接调用. Python之调用函数 Python内置了很多有用的函数,我们可以直接调用. 要调用一个函数,需 ...

  3. python——入门系列(一)索引与切片

    1.索引和切片:python当中数组的索引和其他语言一样,从0~n-1,使用索引的方法也是中括号,但是python中的切片的使用简化了代码 索引:取出数组s中第3个元素:x=s[2] 切片:用极少的代 ...

  4. python入门简介

    Python前世今生 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程序,作为ABC ...

  5. Python基本语法[二],python入门到精通[四]

    在上一篇博客Python基本语法,python入门到精通[二]已经为大家简单介绍了一下python的基本语法,上一篇博客的基本语法只是一个预览版的,目的是让大家对python的基本语法有个大概的了解. ...

  6. python入门以及接口自动化实践

    一.Python入门必备基础语法# 标识符:python中我们自己命名的都是标识符# 项目名 包名 模块名# 变量名 函数名 类名# 1:字母 下划线 数字组成 命名的时候不能以数字开头# 2:见名知 ...

  7. python入门篇之介绍和流程控制(一)

    Python入门 一.第一句python代码 很多语言的第一句python代码都是以“你好,世界”开始的,那么我们的python也是如此. 在 /home/dev/ 目录下创建 hello.py 文件 ...

  8. Python入门篇-装饰器

    Python入门篇-装饰器 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.装饰器概述 装饰器(无参) 它是一个函数 函数作为它的形参 返回值也是一个函数 可以使用@functi ...

  9. python入门练习题1

    常见python入门练习题 1.执行python脚本的两种方法 第一种:给python脚本一个可执行的权限,进入到当前存放python程序的目录,给一个x可执行权限,如:有一个homework.py文 ...

随机推荐

  1. git使用教程&&问题列表

    git教程[转] http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000 git push ...

  2. LTDC/DMA2D—液晶显示

    本章参考资料:<STM32F4xx 参考手册 2>.<STM32F4xx 规格书>.库帮助文档<stm32f4xx_dsp_stdperiph_lib_um.chm> ...

  3. Jar包版本查看方法

    原文:  https://blog.csdn.net/u011287511/article/details/66973559 打开Java的JAR文件我们经常可以看到文件中包含着一个META-INF目 ...

  4. vs2010程序运行出错 link : fatal error lnk1123: 转换到 coff 期间失败: 文件无效或损坏

    vs2010程序运行出错 link : fatal error lnk1123: 转换到 coff 期间失败: 文件无效或损坏 2014-03-27 11:34杜_柏 | 浏览 36144 次 请问这 ...

  5. 【C#】解析XML

    最近在尝试用WPF搞点桌面小应用. C#中使用System.Xml.XmlDocument类对XML文件进行操作. 文档详情如下: https://msdn.microsoft.com/en-us/l ...

  6. OK335xS 256M 512M nand flash make ubifs hacking

    /********************************************************************************* * OK335xs 256M 51 ...

  7. si4438 与 si4432通讯

    http://www.nicerf.cn/_d275147664.htm http://wenku.baidu.com/view/2109573caf1ffc4ffe47ac8c.html si446 ...

  8. 【SpringMVC笔记】第五课 改进Handler处理器和视图解析器

    第四课 已经对注解的映射器和适配器进行了改进. 接下来需要对Handler处理器和视图解析器进行改进. <!-- 配置handler处理器 --> <bean class=" ...

  9. /dev/sdxx is apparently in use by the system; will not make a filesystem here! 解决方法

    在存储上共享了一个500G的空间,映射到Linux系统提供上,环境由2个节点组成. 一. 测试一: 直接mount 用fdisk 格式化之后如下: [root@rac1 u01]# fdisk -l ...

  10. DataGridView使用技巧十三:点击列头实现升序和降序排序

    DataGridView 列有三种排序模式.每一列的排序模式是通过该列的 SortMode 属性指定的,该属性可以设置为以下的 DataGridViewColumnSortMode 枚举值之一. Da ...