Latest web development tutorials

Pythonのendswith()メソッド

Python文字列 Python文字列


説明

Pythonのendswith()メソッドは、指定された接尾辞を持つエンドがそうでなければFalse、Trueを返した場合、文字列は、指定した接尾辞で終了するかどうかを決定するために使用されます。 オプションのパラメータは「開始」と「終了」の検索文字列の開始と終了位置のために。

文法

endswith()メソッドの構文:

str.endswith(suffix[, start[, end]])

パラメータ

  • 接尾 - パラメータが文字列または要素にすることができます。
  • スタート - 文字列の開始位置を。
  • エンド - 文字の終了位置。

戻り値

文字列が含まれている場合は、指定サフィックスがそうでなければFalse、Trueを返します。

次の例では、endswith()インスタンスメソッドを示しています。

#!/usr/bin/python

str = "this is string example....wow!!!";

suffix = "wow!!!";
print str.endswith(suffix);
print str.endswith(suffix,20);

suffix = "is";
print str.endswith(suffix, 2, 4);
print str.endswith(suffix, 2, 6);

次のように上記の出力結果の例は次のとおりです。

True
True
True
False

Python文字列 Python文字列