1. s.find(t): 字符串s中包含t的第一个索引(没找到返回-1)

2. s.rfind(t): 字符串s中包含t的最后一个索引(没找到返回-1)

3. s.index(t): 与s.find(t)功能类似,但没找到引起ValueError

4. s.rindex(t): 余s.rfind(t)功能类似,但没找到引起ValueError

5. s.join(text): 连接字符串s与text中的词汇

6.s.split(t): 在所有找到t的位置将s分割成链表(默认为空白符)

7. s.splitlines(): 将s按行分割成字符串链表

8.s.lower(): 将字符串s小写

9. s.upper(): 将字符串s大写

10. s.titlecase(): 将字符串s首字母大写

11. s.strip(): 返回一个没有首尾空白字符的s的复制

12. s.replace(t, u): 用u替换s中的t

 

下面介绍一个不常用的包,它的功能是防止行尾溢出:

textwrap模块

>>> from textwrap import fill
>>> format='%s (%d),'
>>> pieces=[format % (word, len(word)) for word in saying]
>>> output= ' '.join(pieces)
>>> wrapped=fill(output)
>>> print wrapped 

 

posted on 2017-06-08 21:17  寒若雪  阅读(337)  评论(0编辑  收藏  举报