Python3 中的 endswith(suffix ,begin=

首页 / Python3入门教程 / Python3 中的 endswith(suffix ,begin=

Python的 endswith()方法返回以指定子字符串结尾的字符串的true,否则返回false。

endswith - 语法

endswith(suffix[, start[, end]])

endswith - 参数

  • suffix - 一个子字符串
  • start   -  范围的开始索引
  • end     -  范围的最后一个索引

开始和结束两个参数都是可选的。

endswith - 返回类型

它返回布尔值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

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

从0开始学架构 -〔李运华〕

Java核心技术面试精讲 -〔杨晓峰〕

性能测试实战30讲 -〔高楼〕

后端存储实战课 -〔李玥〕

罗剑锋的C++实战笔记 -〔罗剑锋〕

软件设计之美 -〔郑晔〕

分布式系统案例课 -〔杨波〕

超级访谈:对话汤峥嵘 -〔汤峥嵘〕

手把手带你写一个 MiniTomcat -〔郭屹〕

好记忆不如烂笔头。留下您的足迹吧 :)