String
方法
startswith()
简介
startswith()
方法判断字符串B是否在字符串A某段区域的起始位置,可选的参数可以设定对检查区域的位置和范围进行设置。
语法
strA.startswith(strB, beg = 0, end = len(string))
参数
- strB -- 需要判断是否在字符串A中相应范围起始位置的字符串
- beg -- 设定字符串A中需要判断的区域的起始位置
- end -- 设定字符串A中需要判断的区域的结束位置
返回值
返回bool值作为判断结果。
示例
str = "this is string example....wow!!!";
print str.startswith( 'this' )
print str.startswith( 'hi', 1, 3 )
print str.startswith( 'this', 1, 3 )
结果
True
True
False