摘要:
下文讲述Python中startswith()的方法的功能简介说明,如下所示:
startswith()方法功能:
用于判断字符串是否使用指定前缀开头
当为指定字符串开头时,则返回True,否则返回False
startswith()方法语法
s.startswith(prefix[,start=0[,end=len(S)]])
--------参数说明--------
s:待判断的字符串
prefix:指定前缀,该参数可以是一个字符串或者是一个元素
start:可选参数,字符串中的开始位置索引,默认为0(可单独指定)
end:可选参数,字符中结束位置索引,默认为字符串的长度(不能单独指定)
--------返回值说明--------
当字符串为指定前缀开头,则返回True
否则返回False
例:
字符串之startswith()方法的示例分享
#maomao365.com
#startswith()函数的示例分享
S = "The webSite Name is maomao365.com"
print (S.startswith( 'The' ))
print (S.startswith( 'maomao', 8 ))
print (S.startswith( 'web',4, 19 ))
//输出
True
False
True