Python中字符串匹配函数startswith()函数


1.函数用途含义

Python startswith() 方法用于检查字符串是否是以指定子字符串开头,如果是则返回 True,否则返回 False。如果参数 beg 和 end 指定值,则在指定范围内检查。

2.用法

Str.startswith(str, beg=0,end=len(string));
  • Str是需要匹配的字符串
  • str是待检测子字符串
  • beg默认为0表示从第一个字符开始匹配
  • end表示终止匹配的位置

3.实例

#!/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 );

out:
True
True
False


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM