Simple string match
I want to do a simple string match, searching from the -front- of the string. Are there easier ways to do this with maybe a builtin? (re
seems like overkill)
de开发者_运维百科f matchStr(ipadr = '10.20.30.40', matchIP = '10.20.'):
if ipadr[0:len(matchIP)] == matchIP: return True
return False
def matchStr(ipadr = '10.20.30.40', matchIP = '10.20.'):
return ipadr.startswith(matchIP)
>>> 'abcde'.startswith('abc')
True
'10.20.30.40'.startswith('10.20.')
>>>True
精彩评论