实例
检查字符串是否以标点符号 (.) 结尾:
txt = "Hello, welcome to my world." x = txt.endswith(".") print(x)
定义和用法
如果字符串以指定值结尾,则 endswith() 方法返回 True,否则返回 False。
语法
string.endswith(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)