Pythonの文字列 endswith() 関数は、入力文字列が特定のサフィックスで終わっていれば真を返し、そうでなければ偽を返します。
キーポイント
- 戻り値のタイプ。ブール値(TrueまたはFalse)。
 - パラメータ値。パラメータ: 3つのパラメータがあります。サフィックス、スタート、エンド
 
| パラメータ | |
| サフィックス|チェックする文字列または文字列のタプルにすることができます。これは大文字と小文字を区別します。 | |
| Start|これはオプションで、チェックを開始するインデックスを指定します。 | |
| End|これはオプションで、チェックが終了するインデックスを指定します。 | 
Python String endswith() 構文
string.endswith(suffix[, start[, end]]).
String endswith() の例
例 1:
str= 'Engineering Discipline'
print(str.endswith('Discipline'))  # True
 | 
例2: オフセットの提供
str = 'Engineering is an interesting discipline'
print(str.endswith('discipline', 2))  # True
print(str.endswith('Engineering', 10))  # False
 | 
例3: len() 関数と endswith() 関数の併用
str = 'Engineering is an interesting discipline'
print(str.endswith('discipline', 11, len(str)))  # True
print(str.endswith('Engineering', 0, 11))  # True
print(str.endswith('Python', 8))  # False
 | 
例4:
str = 'C++ Java Python'
print(str.endswith(('Perl', 'Python')))  # True
print(str.endswith(('Java', 'Python'), 3, 8))  # True
 | 
まとめ
Python String endswith() 関数は、文字列が与えられたサフィックスで終わっているかどうかをチェックするユーティリティです。