Python endswith()
方法用于判断字符串是否以指定后缀结尾,
如果以指定后缀结尾返回True,否则返回False。
# 想象力让我们突破极限。
my_str = "The power of imagination makes us infinite"
print("infinite", my_str.endswith("infinite"))
print("te", my_str.endswith("te"))
print("power", my_str.endswith("power"))
if my_str.endswith("infinite"):
print("添加句号")
print(my_str + ".")
True
True
False
添加句号
The power of imagination makes us infinite.
引申
start参数
end参数
str.endswith(suffix, start, end)