Python 中的 startswith(str, beg=0,en

首页 / Python2入门教程 / Python 中的 startswith(str, beg=0,en

Python startswith()检查字符串是否以str开头,可选地限制与给定索引start和end的匹配。

startswith - 语法

以下是startswith()方法-的语法

str.startswith(str, beg=0,end=len(string));
  • str   -  这是要检查的字符串。

  • beg  -  这是用于设置匹配边界的起始索引的可选参数。

  • end  -  这是结束匹配边界的开始索引的可选参数。

startswith - 返回值

如果找到匹配的字符串,则此方法返回true,否则返回false。

startswith - 示例

以下示例显示startswith()方法的用法。

无涯教程网

#!/usr/bin/python

str="this is string example....wow!!!";
print str.startswith( 'this' )
print str.startswith( 'is', 2, 4 )
print str.startswith( 'this', 2, 4 )

当无涯教程运行上面的程序时,它产生以下输出-

True
True
False

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

如何设计一个秒杀系统 -〔许令波〕

Spring Boot与Kubernetes云原生微服务实践 -〔杨波〕

ZooKeeper实战与源码剖析 -〔么敬国〕

设计模式之美 -〔王争〕

NLP实战高手课 -〔王然〕

技术管理案例课 -〔许健〕

分布式金融架构课 -〔任杰〕

超级访谈:对话道哥 -〔吴翰清(道哥)〕

AI大模型企业应用实战 -〔蔡超〕

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