擅长:python、mysql、java
<p>请注意,如果您有很长的文件,一次将它们全部读入内存可能不是一个好主意。在这种情况下,您可以同时使用<code>zip</code>对它们进行迭代:</p>
<pre><code>with open("file1.txt") as file1, open("file2.txt") as file2:
for line1, line2 in zip(file1, file2):
print(int(line1) + int(line2))
</code></pre>