python中startswith()函数的用法

更新时间:2023-07-03 09:51:07 阅读: 评论:0

害怕的英文python中startswith()函数的⽤法startswith()函数
描述:判断字符串是否以指定字符或⼦字符串开头。
语法:dswith("suffix", start, end) 或
社交礼仪培训str[start,end].endswith("suffix")    ⽤于判断字符串中某段字符串是否以指定字符或⼦字符串结尾。
—> bool    返回值为布尔类型(True,Fal)
suffix — 后缀,可以是单个字符,也可以是字符串,还可以是元组("suffix"中的引号要省略)。
start —索引字符串的起始位置。
end — 索引字符串的结束位置。
注意:空字符的情况。返回值通常也为True
程序⽰例:
str = "hello,i love python"
print("1:",str.startswith("h"))
功夫熊猫感恩节print("2:",str.startswith("l",2,10))# 索引 llo,i lo 是否以“n”结尾。
print("3:",str.startswith("")) #空字符
注定爱你print("4:",str[0:6].startswith("h")) # 只索引  hello,韩式男士发型
print("5:",str[0:6].startswith("e"))
print("6:",str[0:6].startswith(""))
print("7:",str.startswith(("h","z")))#遍历元组的元素,存在即返回True,否者返回Fal
print("8:",str.startswith(("k","m")))
程序运⾏结果:
英文好听的名字1: True
2: True
3: True
4: True
red tube5: Falwipe out
6: True
7: True有志者事竟成英文
8: Fal去痘小窍门

本文发布于:2023-07-03 09:51:07,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/78/1075844.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:字符串   字符   是否   指定   返回值   元素
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图