python endswith

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

标签:endswith python

免责声明:本内容来自橡树街平台创作者或收集于互联网公开资源,不代表橡树街网的观点和立场。如有侵权内容,请联系我们删除。联系邮箱:ihuangque@qq.com
相关推荐
  • Python工程师工作内容
    Python工程师工作内容
    08-05
  • python list函数
    python list函数
    08-05
  • python scipy
    python scipy
    08-05
  • python学完能干什么
    python学完能干什么
    08-05
  • python需要学习什么
    python需要学习什么
    08-05
  • python基于什么语言
    python基于什么语言
    08-05
  • python是什么类型的语言
    python是什么类型的语言
    08-05
  • python是什么意思啊
    python是什么意思啊
    08-05
  • python要怎么学
    python要怎么学
    08-05
  • python是干什么用的
    python是干什么用的
    08-05