如何在一个文件的一行中同时写入多个字符串和多个变量输出来输出? 我知道 write() 只接受一个参数,但理想情况下这是我想要实现的目标:
write('Temperature is', X , 'and pressure is', Y)
结果将是一个表格。
你能帮忙吗?
最佳答案
write('Temperature is {0} and pressure is {1})'.format(X,Y))
如果你想更好地控制输出,你可以这样做:
X = 12.3
Y = 1.23
write('Temperature is {0:.1f} and pressure is {1:.2f})'.format(X,Y))
# writes 'Temperature is 12.3 and pressure is 1.2'
关于python - 从 Python3 写入 "table",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4129624/