Pythonのrstrip()メソッド
説明
文字列の指定した文字列の末尾を削除するには、Pythonのrstrip()(デフォルトはスペースです)。
文法
rstrip()メソッドの構文:
str.rstrip([chars])
パラメータ
- 文字 - 指定された文字が削除された(デフォルトは空白です)
戻り値
後に指定した文字列で文字列の終了時に削除新しい文字列の生成を返します。
例
次の例では、使用するrstrip()関数を示しています。
#!/usr/bin/python str = " this is string example....wow!!! "; print str.rstrip(); str = "88888888this is string example....wow!!!8888888"; print str.rstrip('8');
次のように上記の出力結果の例は次のとおりです。
this is string example....wow!!! 88888888this is string example....wow!!!