Python的
endswith(suffix[, start[, end]])
开始和结束两个参数都是可选的。
它返回布尔值True或False。
一个返回true的简单示例,因为它以点(.)结尾。
# Python endswith() function example # 变量声明 str = "Hello this is javatpoint." isends = str.endswith(".") # 显示结果 print(isends)
输出:
True
它返回false,因为字符串不以is结尾。
# Python endswith() function example # 变量声明 str = "Hello this is javatpoint." isends = str.endswith("is") # 显示结果 print(isends)
输出:
False
在这里,无涯教程提供方法开始搜索的范围的起始索引。
# Python endswith() function example # 变量声明 str = "Hello this is javatpoint." isends = str.endswith("is",10) # 显示结果 print(isends)
输出:
False
它返回true,因为第三个参数在索引13处停止了该方法。
# Python endswith() function example # 变量声明 str = "Hello this is javatpoint." isends = str.endswith("is",0,13) # 显示结果 print(isends)
输出:
True
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)