用Python3写一张“表”

2024-04-23 06:17:46 发布

您现在位置:Python中文网/ 问答频道 /正文

如何将多个字符串和多个变量输出同时写入文件中的一行进行输出? 我知道write()只接受一个参数,但理想情况下这是我要实现的:

write('Temperature is', X , 'and pressure is', Y)

结果就是一张表格。在

你能帮忙吗?在


Tags: and文件字符串参数is情况表格write
2条回答
f = open("somefile.txt", "w")
print('Temperature is', X , 'and pressure is', Y, file=f)
write('Temperature is {0} and pressure is {1})'.format(X,Y))

如果您想对输出进行更多控制,可以执行以下操作:

^{pr2}$

文档和示例:http://docs.python.org/py3k/library/string.html

相关问题 更多 >