1、

S.partition(sep) -> (head, sep, tail)

Search for the separator sep in S, and return the part before it,
the separator itself, and the part after it. If the separator is not
found, return S and two empty strings.

分割作用,参数为分割字符,分为三部分,(参数前,参数,参数后);如果参数没有找到,返回原字符串和两个空字符串。参数有多个,以第一个为准。S.partition(sep) -> (head, sep, tail)   以最后一个参数为准。

 >>> a
'acbsdwf124'
>>> a.partition('d')
('acbs', 'd', 'wf124')
>>> a.partition('i')
('acbsdwf124', '', '')
>>> a.partition('sd')
('acb', 'sd', 'wf124')
>>> a='hello world hello huhu !'
>>> a.partition('hello')
('', 'hello', ' world hello huhu !')

2、

S.replace(old, new[, count]) -> str

Return a copy of S with all occurrences of substring
old replaced by new. If the optional argument count is
given, only the first count occurrences are replaced.

替换

 >>> a='1a2a3a4a5a'
>>> a.replace('a','b')
'1b2b3b4b5b
>>> a.replace('a','b',)
'0b1b2b3a4a5a #替换前三个

3、

S.split(sep=None, maxsplit=-1) -> list of strings

Return a list of the words in S, using sep as the
delimiter string. If maxsplit is given, at most maxsplit
splits are done. If sep is not specified or is None, any
whitespace string is a separator and empty strings are
removed from the result.

S.rsplit(sep=None, maxsplit=-1) -> list of strings  第二个参数,从右侧开始划分。

文本解析,默认为空格,空格将被移除。返回字符串列表。

 >>> a='hello world ,huhu !'
>>> a.split()
['hello', 'world', ',huhu', '!']
>>> a.split(',')
['hello world ', 'huhu !']
>>> a='hello:world:huhu'
>>> a.split(':',)
['hello', 'world', 'huhu']
>>> a.split(':',)
['hello', 'world:huhu'] #从左侧划分。

S.splitlines([keepends]) -> list of strings

Return a list of the lines in S, breaking at line boundaries.
Line breaks are not included in the resulting list unless keepends
is given and true

 >>> a="""hello world!
... second line
... splitlins test
... """
>>> a.splitlines()
['hello world!', 'second line', 'splitlins test']
>>> a.splitlines(True) #保留行分割符
['hello world!\n', 'second line\n', 'splitlins test\n']

4、

S.swapcase() -> str

Return a copy of S with uppercase characters converted to lowercase
and vice versa.

字母大小写转换

 >>> a='ABCDefgh'
>>> a.swapcase()
'abcdEFGH'

5、

S.zfill(width) -> str

Pad a numeric string S with zeros on the left, to fill a field
of the specified width. The string S is never truncated.

给定长度,左侧添零补充

 >>> a
'ABCDefgh'
>>> a.zfill()
'00ABCDefgh'

最新文章

  1. ios -- 教你如何轻松学习Swift语法(一)
  2. java.lang.UnsupportedClassVersionError
  3. Ubuntu 针对 SSD 的优化方案
  4. makefile_2
  5. windows7安装远程服务器AD域管理工具
  6. Ubunut 13.04下配置memcached、 python MySQLDB,python-memcache模块等
  7. Android流式布局实现
  8. CocoaPods 安装和使用
  9. php按照奖品百分比随机抽奖代码分析
  10. MVC4新功能...压缩和合并js文件和样式文件
  11. oracle 表导入到powerDesigner 中
  12. MongoDB学习之--增删改查(2)
  13. Java面试宝典
  14. 没人看系列-----html随笔
  15. LeetCode 96 - 不同的二叉搜索树 - [DP]
  16. Matlab-7:偏微分方程数值解法-李荣华-有限元解导数边界值的常微分(Galerkin方法)
  17. H5 贪吃蛇源码
  18. Python学习笔记第五周
  19. 机器学习入门-文本数据-构造词频词袋模型 1.re.sub(进行字符串的替换) 2.nltk.corpus.stopwords.words(获得停用词表) 3.nltk.WordPunctTokenizer(对字符串进行分词操作) 4.np.vectorize(对函数进行向量化) 5. CountVectorizer(构建词频的词袋模型)
  20. 从实例角度分析java的public、protected、private和default访问权限

热门文章

  1. Quartz.Net - Lesson2: 任务和触发器
  2. tornado+ansible+twisted+mongodb运维自己主动化系统开发(四)
  3. Array的push与unshift方法性能比较分析
  4. Unity中surfaceShader的处理机制和finalColor
  5. php闭包简单实例
  6. 素数定理 nefu 117
  7. 【BZOJ3270】博物馆 期望DP+高斯消元
  8. 【BZOJ3143】[Hnoi2013]游走 期望DP+高斯消元
  9. python的协程和_IO操作
  10. Java编程中的一些常见问题汇总