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的简单示例,因为它以点(.)结尾。

链接:https://www.learnfk.comhttps://www.learnfk.com/python3/python-string-endswith-method.html

来源:LearnFk无涯教程网

# 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开始学大数据 -〔李智慧〕

面试现场 -〔白海飞〕

DevOps实战笔记 -〔石雪峰〕

爆款文案修炼手册 -〔乐剑峰〕

朱涛 · Kotlin编程第一课 -〔朱涛〕

Kubernetes入门实战课 -〔罗剑锋〕

现代C++20实战高手课 -〔卢誉声〕

结构沟通力 -〔李忠秋〕

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