更新时间:2023-02-22 08:07:04
要在结尾处仅删除换行符:
To remove just the newline at the end:
line = line.rstrip('\n')
readline
保留换行符的原因是,您可以区分空白行(具有换行符)和文件末尾(空字符串).
The reason readline
keeps the newline character is so you can distinguish between an empty line (has the newline) and the end of the file (empty string).