# 示例代码:使用 endswith 方法检查字符串是否以指定后缀结尾
# 定义一个字符串
text = "hello world"
# 使用 endswith 检查字符串是否以 "world" 结尾
if text.endswith("world"):
print("字符串以 'world' 结尾")
else:
print("字符串不以 'world' 结尾")
# 使用 endswith 检查字符串是否以 "python" 结尾
if text.endswith("python"):
print("字符串以 'python' 结尾")
else:
print("字符串不以 'python' 结尾")
endswith 是 Python 字符串的一个方法,用于检查字符串是否以指定的后缀结尾。True,否则返回 False。text,然后使用 endswith 方法分别检查它是否以 "world" 和 "python" 结尾,并根据结果输出相应的信息。上一篇:python 换行
下一篇:python @
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站