Python文字列endswith()メソッド
例
文字列が句読記号(。)で終わっているかどうかを確認します。
txt = "Hello, welcome to my world."
x = txt.endswith(".")
print(x)
定義と使用法
endswith()
文字列が指定された値で終了する場合、メソッドはTrueを返し、それ以外の場合はFalseを返します。
構文
string.endswith(value, start, end)
パラメータ値
Parameter | Description |
---|---|
value | Required. The value to check if the string ends with |
start | Optional. An Integer specifying at which position to start the search |
end | Optional. An Integer specifying at which position to end the search |
その他の例
例
文字列が「myworld。」というフレーズで終わっているかどうかを確認します。
txt = "Hello, welcome to my world."
x = txt.endswith("my world.")
print(x)
例
位置5から11が「myworld」というフレーズで終わっているかどうかを確認します。
txt = "Hello, welcome to my world."
x = txt.endswith("my world.",
5, 11)
print(x)