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')这里是从左到右开始匹配的。
【相关推荐】
立即学习“Python免费学习笔记(深入)”;
3. MySQL之-数据表分区技术PARTITION的代码示例浅析
以上就是分享一篇Python中字符串函数 (partition)详解的详细内容,更多请关注php中文网其它相关文章!
python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号