python之判断字符串以何关键字开头

(str.startswith('关键字') is True:以关键字开头 False:不以关键字开头
还可以指定关键字所处位置:
#!/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 );
posted @ 2021-06-30 13:30  mollyliu  阅读(237)  评论(1)    收藏  举报