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
相关文章
相关标签/搜索