博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

python学习之endswith()

Posted on 2017-10-12 16:25  开飞机的贝塔  阅读(177)  评论(0编辑  收藏  举报

定义:

Python endswith() 方法用于判断字符串是否以指定后缀结尾,如果以指定后缀结尾返回True,否则返回False。可选参数"start"与"end"为检索字符串的开始与结束位置。

语法:

str.endswith(suffix[, start[, end]])

例子:

#!/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