开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜