Python 字符串 endswith() 方法
定义和用法
如果字符串以指定值结尾,则 endswith() 方法返回 True,否则返回 False。
语法
string.endswith(value, start, end)
参数值
| 参数 | 描述 | 
|---|---|
| value | 必需。检查字符串是否以之结尾的值。 | 
| start | 可选。整数。规定从哪个位置开始检索。 | 
| end | 可选。整数。规定从哪个位置结束检索。 | 
更多实例
实例
检查字符串是否以短语 "my world." 结尾:
txt = "Hello, welcome to my world."
x = txt.endswith("my world.")
print(x)
实例
检查位置 5 至 11 是否以短语 "my world." 结尾:
txt = "Hello, welcome to my world."
x = txt.endswith("my world.", 5, 11)
print(x)
