只使用 split 怎么样:str = "Jack;10;20;30\n Omar;20,24,25\n Carl;30;30;30\n"output_list = [line.split(";")[1:] for line in str.split("\n")]output = [";".join(line) for line in output_list]>>>['10;20;30', '20,24,25', '30;30;30', '']
您可以split将字符串、结果列表切片,然后join使用相同的分隔符将切片列表重新转换为字符串:s = "Jack;10;20;30\n Omar;20,24,25\n Carl;30;30;30\n"print('\n'.join(';'.join(l.split(';')[1:]) for l in s.splitlines()))这输出:10;20;3020,24,2530;30;30