python字符串
来源:互联网 发布:51testing 软件测试 编辑:程序博客网 时间:2024/06/08 10:06
Python 中字符串被定义为引号之间的字符集合。Python 支持使用成对的单引号或双引号, 三引号(三个连续的单引号或者双引号)可以用来包含特殊字符。使用索引运算符( [ ] )和切 片运算符( [ : ] )可以得到子字符串。字符串有其特有的索引规则:第一个字符的索引是 0, 最后一个字符的索引是 -1
加号( + )用于字符串连接运算,星号( * )则用于字符串重复。下面是几个例子:
>>> pystr = 'Python'>>> iscool = 'is cool!'>>> pystr[0]'P'>>> pystr[2:5]>'tho'>>> iscool[:2]'is'>>> iscool[3:]'cool!'>>> iscool[-1]'!'>>> pystr + iscool'Pythonis cool!'>>> pystr + ' ' + iscool'Python is cool!'>>> pystr * 2'PythonPython'>>> '-' * 20'--------------------'>>> pystr = '''python... is cool'''>>> pystr'python\nis cool'>>> print pystrpythonis cool>>>
0 0
- Python字符串
- Python 字符串
- python字符串
- python 字符串
- 【python】-字符串
- python 字符串
- python字符串
- python 字符串
- python,字符串
- python 字符串
- Python字符串
- Python字符串
- python字符串
- Python 字符串
- python 字符串
- Python 字符串
- Python字符串
- python 字符串
- 删除链表中某结点
- 技术人生:故事之三十三你做过经理吗?
- OC-集合2(字典,NSSet)
- 管道的应用(pipe)《深入分析Linux内核源码》 http://blog.csdn.net/wangpengqi/article/details/7996182
- 如何解决C/C++中stack overflow问题
- python字符串
- 用win32api写的贪吃蛇
- Java中 set,list,array(集合与数组)、Map相互转换
- 我选择死亡
- windows 下修复Ubuntu启动项
- 图像算法---基于局部均值的锐化算法研究
- LintCode 字符串查找
- poj 1782 Run Length Encoding 自动机处理字符串
- 设计模式-2-单例模式