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