Python 中的 endswith(suffix, beg=0,

首页 / Python2入门教程 / Python 中的 endswith(suffix, beg=0,

Python字符串方法endswith()如果字符串以指定的后缀结束,则返回True,否则返回False,可以选择限制与给定索引的匹配start和end。

endswith - 语法

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

endswith - 返回值

如果字符串以指定的后缀结束,则为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

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

Service Mesh实践指南 -〔周晶〕

Java核心技术面试精讲 -〔杨晓峰〕

Swift核心技术与实战 -〔张杰〕

编译原理之美 -〔宫文学〕

SRE实战手册 -〔赵成〕

分布式数据库30讲 -〔王磊〕

Go 并发编程实战课 -〔晁岳攀(鸟窝)〕

手把手带你搭建秒杀系统 -〔佘志东〕

结构学习力 -〔李忠秋〕

好记忆不如烂笔头。留下您的足迹吧 :)