4
如何在文件的一行中写入多个字符串和多个变量输出以输出? 我知道,写()只接受一个参数,尽管这个理想是什么,我想要实现:从Python3写入“表”
write('Temperature is', X , 'and pressure is', Y)
其结果将是一个表。
你能帮忙吗?
如何在文件的一行中写入多个字符串和多个变量输出以输出? 我知道,写()只接受一个参数,尽管这个理想是什么,我想要实现:从Python3写入“表”
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'
f = open("somefile.txt", "w")
print('Temperature is', X , 'and pressure is', Y, file=f)
他要输出到文件。 – 2010-11-09 01:28:05