写入空文件
filename = 'programming.txt'
with open(filename,'w') as file_object:
file_object.write("I love programming.")
生成了txt的文件 programing
内容如下:
将第二个实参进行修订,由w→a,可以对原txt文件进行“附加模式”的内容添加
filename = 'programming.txt'
# with open(filename,'w') as file_object:
# file_object.write("I love Python.")
with open(filename,'a') as file_object:
file_object.write("C language is the next turn.")
使用换行符,实现在txt文件中的文字自动换行
filename = 'programming.txt'
with open(filename,'w') as f:
f.write("I love programming.n")
f.write("I love creating new games.n")
结论如下:
I love programming.
I love creating new games.
最后
以上就是还单身盼望最近收集整理的关于py code diary everyday】2023-02-06 sec的全部内容,更多相关py内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复