4.5.6 startswith函数

更新于 2026年10月13日 版权声明
4.5.6 startswith函数

检查字符串是否以指定字串开头,如果是则返回 True,否则返回 False。如果设置开始和结束位置下标,则在指定范围内检查。

(1)语法

字符串序列.startswith(子串,开始位置下标,结束位置下标)(https://www.daowen.com)

(2)快速体验

mystr = "hello world and hbes and hbeszy and Python "
print(mystr.startswith('hello'))# 结果:True
print(mystr.startswith('hello', 5, 20))# 结果:False

✍AI写作