endswith()方法返回true,如果字符串以指定后綴結尾,否則返回(False可選限制的匹配從給定的索引開始和結束)。
語法
以下是endswith()方法的語法:
str.endswith(suffix[, start[, end]])
參數
suffix -- 這可能是一個字符串或者是元組用于查找后綴。 start -- 切片從此開始 end -- 切片到此為止返回值
如果字符串以指定的后綴結束此方法返回true,否則返回false。
例子
下面的例子顯示了endswith()方法的使用。
#!/usr/bin/pythonstr = "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);
當我們運行上面的程序,它會產生以下結果:
TrueTrueTrueFalse
新聞熱點
疑難解答