endswith

概要Description

签名

s.endswith(sub: str, start?: int, end?: int): bool

功能

检测并返回 s 是不是 以 sub 作为结尾

start 和 end 可以从 s 中切出局部,比较 局部是否以 sub 作为结尾

广告

案例Examples

正常情况

1 2 =
s = 'page.html'result = s.endswith('.html')True

start 控制

传输 的 第 2 个 参数,将被作为 start

查找时,将从 s 的 start 开始 到 s 结束,切出 子字符串,比较子字符串是否以 sub 结尾

包含 start

1 2 =
s = 'page.html'result = s.endswith('.html', 2)True
注意

即便原字符串 s 是以 sub 作为结尾,但切出的字符串长度不足 sub 时,认定判定失败

1 2 =
s = 'page.html'result = s.endswith('.html', 6)False

end 控制

传输 的 第 3 个 参数,将被作为 end

结合前面的 2 个参数,查找时,将从 s 的 start 开始 到 s 的 end 结束,切出 子字符串,

比较子字符串是否以 sub 结尾

包含 start,不包含 end

1 2 =
s = '[page.html]'result = s.endswith('.html', 1, 10)True
广告

ZZAX 微信公众

文档一更新,立刻告诉你