python字符串
2015-09-20 20:03
645 查看
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 pystr python is cool >>>
相关文章推荐
- python源码剖析
- python中元组(tuple)的用法
- python中列表的常用方法
- multiprocessing module in python(转)
- ubuntu12.04 set python2.7 opencv2.4.9
- Python+OpenCV学习(18)---双目视觉深度信息恢复
- python代码覆盖率工具——coverage
- Python学习笔记16:标准库多线程(threading包裹)
- Python 时间戳与时间字符串互相转
- Python中super的用法
- 配置vim Python IDE 开发环境
- ubuntu下python2.7与python3.4共存及切换
- mamp 下 的mysql 安装 python 的 mysql 接口 MySQLdb
- python字符串
- python安装包管理工具pip以及修改pip源
- 给numpy矩阵添加一列
- Python:类属性,实例属性,私有属性与静态方法,类方法,实例方法
- 【Python系列4】国外程序员整理的机器学习资源大全——Python篇
- 执行python文件
- python serial 模块