任务要求:将字符串拆分,逐句写入文本文档,实现以下效果图
知识点:文件写入、字符串分割、字符串首尾去空格
参考答案:
# coding=utf-8
"""
Author: 笨笨
Date: 2021-01-01
"""
f = open("demo.txt", "a")
str_1 = "2020有毒, 已然过去, 山河无恙, 人间皆安, 千帆过尽, 向新而行"
list_1 = str_1.split(",")
for s in list_1:
f.write(s.strip()+"\n")
f.close()