4.5.7 endswith函数

更新于 2026年10月13日 版权声明
4.5.7 endswith函数

检查字符串是否以指定子串结尾,如果是则返回 True,否则返回 False。如果设置开始和结束位置下标,则在指定范围内检查。

(1)语法

字符串序列.endswith(子串, 开始位置下标, 结束位置下标)(https://www.daowen.com)

(2)快速体验

mystr = "hello world and hbes and hbeszy and Python"
print(mystr.endswith('Python'))# 结果:True
print(mystr.endswith('python'))# 结果:False
print(mystr.endswith('Python', 2, 20))# 结果:False

✍AI写作