这是简单的解决方案。如果您的值以逗号分隔,则可以使用 split() 方法:f = open("data.txt", "r")sumofn = 0for i in range(1, 10): for x in f.readlines(): x = int(x) sumofn += xprint(sumofn)这里也是拆分()方法。如果您的值以逗号分隔,以空格分隔,则使用它:f = open("data.txt", "r")sumofn = 0for i in range(1, 10): for x in f.readlines(): y = x.split(',') for x in y: x = int(x) sumofn += xprint(sumofn)