宇辰恒笛

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

partition()从左向右寻找,以字符串中的某个元素为中心将左右分割共分割成三个元素并放入到元组中

partition()从右向左寻找,以字符串中的某个元素为中心将左右分割共分割成三个元素并放入到元组中

举个例子:

1 a = "hello is goog is world"
2 a1 = a.partition("is")
3 print(a1)

输出结果:

('hello ', 'is', ' goog is world')

我们以左侧寻找到的首个is为中心将字符串分割成了三个元素放到了元组中

 

1 b = "hello is goog is world"
2 b1 = b.rpartition("is")
3 print(b1)

输出结果:

('hello is goog ', 'is', ' world')

我们以由侧寻找到的首个is为中心将字符串分割成了三个元素放到了元组中

posted on 2019-04-09 10:10  宇辰滴滴  阅读(573)  评论(0编辑  收藏  举报