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

相关文章:

  • 2022-12-23
  • 2021-09-28
  • 2021-11-11
  • 2022-12-23
猜你喜欢
  • 2021-11-18
  • 2021-08-10
  • 2022-12-23
  • 2021-11-20
  • 2022-12-23
  • 2021-05-19
相关资源
相似解决方案