我是Python新手,正在练习文件操作。我写了这个程序:
myfile = open('test3.txt', 'w+')
myfile.writelines(['Doctor', 'Subramanian', 'Swamy', 'Virat', 'Hindustan', 'Sangam'])
其输出如下:
DoctorSubramanianSwamyViratHindustanSangam
如何在最终输出中的列表项之间添加空格,以便最终输出为Doctor Subramanian Swamy Virat Hindustan Sangam
可以尝试使用相同的.strip()方法剥离它吗
试试看,让我知道
根据我对您问题的理解,您希望在最终输出的列表元素之间添加空格。一种可能的解决办法是:
特别是,此行
myfile.write(l+' ')
将在写入每个元素后添加一个空格相关问题 更多 >
编程相关推荐