Python-string-rstrip
提供:Dev Guides
Python String rstrip()メソッド
説明
Python文字列メソッド* rstrip()*は、すべての_chars_が文字列の末尾(デフォルトの空白文字)から取り除かれた文字列のコピーを返します。
構文
以下は、* rstrip()*メソッドの構文です-
str.rstrip([chars])
パラメーター
- 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!!!