我想做一个简单的字符串匹配,从字符串的 -front- 开始搜索。有没有更简单的方法可以使用内置函数来做到这一点? (re
似乎矫枉过正)
def 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)
关于python - 简单的字符串匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5969465/