python切片的步进、添加、连接简单操作示例
作者:mengtianwxs 时间:2022-09-10 01:26:34
本文实例讲述了python切片的步进、添加、连接简单操作。分享给大家供大家参考,具体如下:
步进切片:
#coding:utf-8
a="123456"
print a[::-1]
#output 654321
print a[::-2]
#output 642
print a[::2]
#output 135
字符串添加:
#coding:utf-8
a='123456789'
a1=[]
a1.extend(a[0:4])
a1.extend(a[4:])
print a1
#output ['1', '2', '3', '4', '5', '6', '7', '8', '9']
连接两个字符串切片:
#coding:utf-8
__author__ = 'Administrator'
import string
a='python is nice'
b='mengtianwxs is a good boy'
print a[:6]+' and '+b[:11]
#output python and mengtianwxs
更多Python相关内容感兴趣的读者可查看本站专题:《Python列表(list)操作技巧总结》、《Python编码操作技巧总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》、《Python入门与进阶经典教程》及《Python文件与目录操作技巧汇总》
希望本文所述对大家Python程序设计有所帮助。
来源:https://blog.csdn.net/mengtianwxs/article/details/51719587
标签:python,切片
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python中的文本相似度的计算方法总结
2021-02-08 08:40:37
用Javascript正则表达式验证Email地址
2009-12-09 15:56:00
解决“引入同一个JS文件在非IE6中正常,但IE6报错”的问题
2009-04-03 11:42:00
在系统崩溃的时候如何恢复原有的数据
2009-01-08 13:26:00
使用GitHub和Python实现持续部署的方法
2022-07-16 22:54:35
![](https://img.aspxhome.com/file/2023/2/93542_0s.png)
使用php操作xml教程
2023-06-14 03:10:45
![](https://img.aspxhome.com/file/2023/0/55570_0s.png)
Python使用QRCode模块生成二维码实例详解
2022-07-04 16:50:44
python基础编程小实例之计算圆的面积
2023-06-07 06:33:14
![](https://img.aspxhome.com/file/2023/4/99414_0s.png)
Python新手如何进行闭包时绑定变量操作
2021-05-01 15:23:55
ASP常见数学函数 Abs Atn Cos 等详解
2008-05-28 12:33:00
ASP实现上传图片自动压缩图片大小
2010-01-25 12:47:00
asp如何用JMail同时给多人发信?
2010-06-12 12:52:00
Python编写可视化界面的全过程(Python+PyCharm+PyQt)
2022-02-23 02:21:36
![](https://img.aspxhome.com/file/2023/1/75261_0s.jpg)
Python中基本数据类型和常用语法归纳分享
2023-09-08 21:08:01
![](https://img.aspxhome.com/file/2023/0/98990_0s.webp)
python虚拟环境模块venv使用及示例
2021-07-21 12:05:48
python用tkinter开发的扫雷游戏
2022-05-16 18:39:40
![](https://img.aspxhome.com/file/2023/8/84978_0s.png)
python 基于opencv 实现一个鼠标绘图小程序
2021-06-20 18:13:05
![](https://img.aspxhome.com/file/2023/7/84087_0s.png)
在ASP.NET 2.0中操作数据之三十七:DataList批量更新
2023-07-23 10:59:03
![](https://img.aspxhome.com/file/2023/3/76343_0s.png)
SQL Server 自动增长清零的方法
2012-01-05 19:07:47
PDO::errorCode讲解
2023-06-08 03:39:17