Python-string-endswith
提供:Dev Guides
Python String endswith()メソッド
説明
Python文字列メソッド* endswith()*は、文字列が指定された_suffix_で終わる場合にTrueを返します。そうでない場合は、指定されたインデックス_start_および_end_とのマッチングをオプションで制限するFalseを返します。
構文
str.endswith(suffix[, start[, end]])
パラメーター
- suffix -これは文字列の場合もあれば、検索するサフィックスのタプルの場合もあります。
- start -スライスはここから始まります。
- end -スライスはここで終了します。
戻り値
文字列が指定されたサフィックスで終わる場合はTRUE、そうでない場合はFALSE。
例
#!/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