这里提到partition()函数,它是干什么的呢,其实这个函数跟split差不多,都是搞切割的。
partition(...)
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.举个例子:
>>> a = 'changzhi1990'
>>> a.rpartition('h')
('changz', 'h', 'i1990')
可以看到返回了一个三元的tuple,分别是‘h’ 的左边的字符串,分割符‘h’本身,和分割符‘h’的右边的字符串。注意:r 代表从右向左开始匹配。
>>> a = 'changzhi1990'
>>> a.partition('h')
('c', 'h', 'angzhi1990')这里是从左到右开始匹配的。
【相关推荐】
10分钟内自己学会PHP其中,第1篇为入门篇,主要包括了解PHP、PHP开发环境搭建、PHP开发基础、PHP流程控制语句、函数、字符串操作、正则表达式、PHP数组、PHP与Web页面交互、日期和时间等内容;第2篇为提高篇,主要包括MySQL数据库设计、PHP操作MySQL数据库、Cookie和Session、图形图像处理技术、文件和目录处理技术、面向对象、PDO数据库抽象层、程序调试与错误处理、A
立即学习“Python免费学习笔记(深入)”;










