str字符串 endswith( ) 方法

描述

endswith() 方法用於判斷字符串是否以指定後綴結尾,若是以指定後綴結尾返回True,不然返回False。可選參數"start"與"end"爲檢索字符串的開始與結束位置。python

語法

endswith()方法語法:spa

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

參數

  • 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
相關文章
相關標籤/搜索