python将变量写入文本中
x=5
y=2
z=x+y
如何把把x、y、z及其值值写入到文本中?
想要的输出结果是:
x=5
y=2
z=7
下面这段哪里有问题?
x=5
y=2
z=x+y
f=open('test-i.dat','a+')
f.write(str("x=")+str(x)+'\n')
f.write(str("y=")+str(y)+'\n')
f.write(str("z=")+str(z)+'\n')
f.close()
你的缩进有问题,这样就好了。
x=5