Latest web development tutorials

Pythonのrstrip()メソッド

Python文字列 Python文字列


説明

文字列の指定した文字列の末尾を削除するには、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!!!

Python文字列 Python文字列