IT科技

當前位置 /首頁/IT科技 > /列表

endswith,python

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

TAG標籤:Python endswith #