startswith() 方法用于判断字符串是否以指定前缀开头,如果是则返回 True,否则返回 False。
startswith() 方法语法:
|
1
|
S.startswith(prefix[,start=0[,end=len(S)]]); |
如果字符串以指定的前缀开头返回 True ,否则返回 False。
以下实例展示了 startswith() 方法的使用方法:
|
1
2
3
4
5
6
|
#!/usr/bin/python3S = "this is string example....wow!!!"print (S.startswith( ‘this‘ ))print (S.startswith( ‘string‘, 8 ))print (S.startswith( ‘this‘, 2, 4 )) |
以上实例输出结果如下:
|
1
2
3
|
TrueTrueFalse |
原文:https://www.cnblogs.com/baoshilin/p/12330948.html