傻子都能看懂的——Python中的endswith方法

代码:

str = "Hello,Python"
suffix = "Python"
print(str.endswith(suffix, 2))

输出:

True

分析:

str.endswith(suffix,2) 中的2是指:从字符串"Hello,Python" 中的位置2,也就是第一个‘l’开始检索,判断是否以suffix结尾,故本题输出 True

猜你喜欢

转载自blog.csdn.net/qq_38890412/article/details/106931394