首页 > 编程语言 > 详细

python学习之endswith()

时间:2017-10-12 16:48:09      阅读:278      评论:0      收藏: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

 

python学习之endswith()

原文:http://www.cnblogs.com/leomei91/p/7656690.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!