まぬねこの足跡。。。

備忘録+たのしさ+ひっそりと

Python - str.rpartition(sep):文字列 最後の位置で2分割+区切り文字

概要

str.rpartition(sep)

str:区切り文字を含んだ文字列
sep:区切り文字

  • 最後の区切り文字で区切った2分割文字列+区切り文字
  • 区切れない時、2つの空文字列とそのまま文字列
  • 組込み型 文字列メソッド

実行結果

print("123,45,6789".rpartition(","))
print("123,45,6789".rpartition(" "))

表示イメージ

('123,45', ',', '6789')
('', '', '123,45,6789')