python中endswith()判断字符串结尾的方法
endswith()方法描述
endswith()方法,在鄙人接触过的几门计算机语言当中好像都有该方法,python内置的字符串方法当中也有该方法,可以用来判断python的字符串对象在指定索引范围内的结尾是否以某个字符或子串。
endswith()参数语法和用法
str.endswith(suffix[, start[, end]])
1、suffix英文的意思是后缀,一般可以是某个字符或字符串;2、start指定endswith()方法作用的起始索引位置,默认为0;3、end为终止索引位置,默认为字符串长度;
endswith()方法返回值
bool类型的值True or False;
endswith()方法实例代码
>>> str = '笨鸟工具,x1y1z1.com'
>>> str.endswith('com')
True
>>> str.endswith('com',0,6)
False