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)
自己动手试一试 »