defdfs(self, s, parts, rs, path): if parts == 4: if s == "": rs.append(".".join(path)) else: return for i in range(1, 4): if i <= len(s) and int(s[:i]) <= 255: if i > 1and s[0] == "0": # 除了0以外不能有03这种以0开头的 break self.dfs(s[i:], parts+1, rs, path+[s[:i]])