python endswith是怎样的呢?下面就让我们一起来了解一下吧:
endswith是属于python下的一个方法,它能够用来判断字符串是否以指定后缀结尾,若是以指定后缀结尾返回True,否则是返回False,其中可以选择参数start与end为检索字符串的开始与结束位置。
endswith()方法的语法格式为:
str.endswith(suffix[, start[, end]])
参数说明:
suffix --该参数能够是一个字符串或是一个元素。
start -- 字符串中的开始位置。
end -- 字符中结束位置。
返回值:
若是字符串中含有指定的后缀则返回True,否则返回False。
参考范例:
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
以上就是小编的分享了,希望能够帮助到大家。
Copyright © 2019- aiwanbo.com 版权所有 赣ICP备2024042808号-3
违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务