rpartition
概要Description
签名
s.rpartition(sep: str): (left: str, sep: str, right: str) | (origin: str, '', '')
功能
在 s 中 从右往左 找到 第一个 sep 出现的位置,使用 sep 切割 s,
返回 切割后 左边的 left,切割符 sep 和 右边的 right 组成的 元祖 tuple
如果没有找到 sep,则 返回 切割前的 s 和 两个 空字符串 组成的 元祖 tuple
返回后,原字符串 s 在调用后保持不变
广告
案例Examples
正常情况
出现一次
1 2 =s = 'page.html'result = s.rpartition('.')('page', '.', 'html')
sep 出现多次
选最右边的
1 2 =s = './page.html'result = s.rpartition('.')('./page', '.', 'html')
没有出现
1 2 =s = '/'result = s.rpartition('.')('/', '', '')
广告