Python3 endswith()方法
目录
描述
Python endswith() 方法用于判断字符串是否以指定后缀结尾,如果以指定后缀结尾返回 True,否则返回 False。可选参数 “start” 与 “end” 为检索字符串的开始与结束位置。
语法
endswith()
方法语法:
str.endswith(suffix[, start[, end]])
参数
- suffix — 该参数可以是一个字符串或者是一个元素。
- start — 字符串中的开始位置。
- end — 字符中结束位置。
返回值
如果字符串含有指定的后缀返回 True,否则返回 False。
实例
以下实例展示了endswith()
方法的实例:
#!/usr/bin/python3 Str='Mybj example....wow!!!' suffix='!!' print (Str.endswith(suffix)) print (Str.endswith(suffix,20)) suffix='run' print (Str.endswith(suffix)) print (Str.endswith(suffix, 0, 19))
以上实例输出结果如下:
True True False False
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
码云笔记 » Python3 endswith()方法
码云笔记 » Python3 endswith()方法