您可以使用列表推导:def repl(a): return [i.replace(" ", ",") for i in a]或遍历列表:def repl(a): end = [] for i in a: end.append(i.replace(" ", ",")) return end在这两种情况下:>>> a = ['viv', 'xyz', 'abc def']>>> repl(a)['viv', 'xyz', 'abc,def']