LoginSignup
2
4

More than 3 years have passed since last update.

python strip(),rstrip() の違い[memo]

Posted at

ちょっと迷ったので備忘録

先頭と末尾から指定文字を削除するのがstr.strip()
末尾だけから削除するのがstr.rstrip()

参考:python reference strip 日本語版

str.strip([chars])
文字列の先頭および末尾部分を除去したコピーを返します。引数 chars は除去される文字集合を指定する文字列です。 chars が省略されるか None の場合、空白文字が除去されます。 chars 文字列は接頭語でも接尾語でもなく、そこに含まれる文字の組み合わせ全てがはぎ取られます:

str.rstrip([chars])
文字列の末尾部分を除去したコピーを返します。引数 chars は除去される文字集合を指定する文字列です。 chars が省略されるか None の場合、空白文字が除去されます。 chars 文字列は接尾語ではなく、そこに含まれる文字の組み合わせ全てがはぎ取られます:

2
4
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4