endswith() 方法用於判斷字符串是否以指定後綴結尾,若是以指定後綴結尾返回True,不然返回False。可選參數"start"與"end"爲檢索字符串的開始與結束位置。python
endswith()方法語法:spa
str.endswith(suffix[, start[, end]])
若是字符串含有指定的後綴返回True,不然返回False。code
如下實例展現了endswith()方法的實例:blog
#!/usr/bin/python3 Str='Runoob example....wow!!!' suffix='!!' print (Str.endswith(suffix)) print (Str.endswith(suffix,20)) suffix='run' print (Str.endswith(suffix)) print (Str.endswith(suffix, 0, 19))
以上實例輸出結果以下:字符串
True
True
False
False