Python 为什么print()会在输出中添加额外的空白?

Python 为什么print()会在输出中添加额外的空白?,python,Python,下面是我的代码,当打印我创建的第二个文件时,我得到一个缩进。 不明白为什么。 因为我正在学习关于我的简单代码的任何其他注释,所以我很乐意接受。谢谢 from sys import argv script, file_name = argv file_object = open(file_name) print(file_object.read()) file_object.close() second_file_name = input("Enter the second file name:

下面是我的代码,当打印我创建的第二个文件时,我得到一个缩进。 不明白为什么。 因为我正在学习关于我的简单代码的任何其他注释,所以我很乐意接受。谢谢

from sys import argv
script, file_name = argv
file_object = open(file_name)
print(file_object.read())
file_object.close()
second_file_name = input("Enter the second file name: \r\n>> ")
second_file_object = open(second_file_name + 'txt', 'w+')
second_file_object.write(input("Now write to your file: \r\n>> "))
second_file_object.seek(0)
print("printing the second file object: \r\n", second_file_object.read())  
# why is the file content indented when printed?
second_file_object.close()
默认情况下,将在每个参数之间添加一个空格

打印*对象,sep='',end='\n',file=sys.stdout,flush=False

如果更改分隔符,可以删除不需要的空格字符

print("printing the second file object:", second_file_object.read(), sep="\n")