網站首頁 學習教育 IT科技 金融知識 旅遊規劃 生活小知識 家鄉美食 養生小知識 健身運動 美容百科 遊戲知識 綜合知識
當前位置:趣知科普吧 > IT科技 > 

endswith|python

欄目: IT科技 / 發佈於: / 人氣:9.79K

endswith是屬於python下的一個方法,它能夠用來判斷字元串是否以指定後綴結尾,若是以指定後綴結尾返回True,否則是返回False,其中可以選擇參數start與end爲檢索字元串的開始與結束位置。

endswith()方法的語法格式爲:

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

python endswith

參數說明:

suffix --該參數能夠是一個字元串或是一個元素。

start -- 字元串中的開始位置。

end -- 字元中結束位置。

返回值:

若是字元串中含有指定的後綴則返回True,否則返回False。

python endswith 第2張

參考範例:

endswith()方法的使用,具體代碼爲:

#!/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

Tags:endswith Python