Python rstripメソッドで末尾の文字列を削除する

環境
Python 3.9.13
Windows 10 Home 64bit
PyCharm 2022.2.1 (Community Edition)

構文
文字列.rstrip(削除する文字列)
文字列の末尾の文字を削除します。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
文字列のコピーを返します。
引数を指定しない場合は、半角スペース、全角スペース、タブなどの空白文字を削除します。
文字列のコピーを返します。 引数を指定しない場合は、半角スペース、全角スペース、タブなどの空白文字を削除します。
文字列のコピーを返します。
引数を指定しない場合は、半角スペース、全角スペース、タブなどの空白文字を削除します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# coding: utf-8
str = "STC-ST"
res = str.rstrip("ST")
print(res)
# coding: utf-8 str = "STC-ST" res = str.rstrip("ST") print(res)
# coding: utf-8

str = "STC-ST"

res = str.rstrip("ST")

print(res)

実行結果
STC-

Python

Posted by arkgame