2.4 python中的字符串、索引和截取 [python入门教程]
2014-01-27 23:15
686 查看
字符串可以用单引号,双引号,三引号成对括起来,索引用[]界定,切片用[:]来省略和连接,这点类似于Matlab。
>>> s1='Python' >>> s2=' is cool!' >>> str=s1+s2 >>> str 'Python is cool!' >>> str[0] 'P' >>> str[2:5] 'tho' >>> str[:2] 'Py' >>> str[3:] 'hon is cool!' >>> str*2 'Python is cool!Python is cool!' >>> '-'*8 '--------' >>> str[-1] '!'字符串下标从0开始,最后一个字符的索引是-1。加号来连接,*用来重复。
>>> str2='Python\n is cool!' >>> str2 'Python\n is cool!' >>> print str2 Python is cool!
相关文章推荐
- 2.3 python中的变量和赋值 [python入门教程]
- python,flask,web,login
- 2.2 python中的操作符 [python入门教程]
- 2.1 python中的print和raw_input语句 [python入门教程]
- Metaprogramming in Python
- python使用os模块的os.walk遍历文件夹
- 1. python语言特点和安装 [python入门教程]
- Ubuntu 13.10 下安装python 3.3 IDLE
- Python字典按值排序、包含字典的列表按字典值排序的方法
- Python 用ctypes观察Python对象的内存结构 -- (转)
- 金山快盘API的python版
- python参考手册--第9章
- python连接hive
- Python标准模块logging
- Python 关于拷贝(copy)汇总(列表拷贝 // 字典拷贝 // 自定义对象拷贝)
- Python中time模块详解(转)
- Python eval 函数说明
- Python自然语言处理(三) -- 利用NLTK进行聚类
- Python自然语言处理(二)--NLTK调用Stanford_NLP_Tools完成NLP任务
- Python自然语言处理(一)--利用NLTK自带方法完成NLP基本任务