【发布时间】:2021-08-14 00:00:37
【问题描述】:
最近开始学习 Python。
我定义了标题和价格。
现在我想让 Python 创建一个文本文件,并将“标题”和“价格”的内容输入到新创建的文本文件中
print(title)
print(price)
fh = open("Price&Title", "w")
fh.write()
fh.close()
上面的这段代码没有用。
【问题讨论】:
标签: python python-3.x
最近开始学习 Python。
我定义了标题和价格。
现在我想让 Python 创建一个文本文件,并将“标题”和“价格”的内容输入到新创建的文本文件中
print(title)
print(price)
fh = open("Price&Title", "w")
fh.write()
fh.close()
上面的这段代码没有用。
【问题讨论】:
标签: python python-3.x
您可以使用print 的file 参数:
fh = open("Price&Title", "w")
print(title, file=fh)
print(price, file=fh)
fh.close()
【讨论】: