gpt4 book ai didi

python - 当我将变量写入文本文件时,为什么会得到 'none'

转载 作者:行者123 更新时间:2023-11-30 22:29:36 25 4
gpt4 key购买 nike

我的代码中出现的问题是任何变量(在本例中为 time 和 option_1 )写入文本文件会输出“none”作为实际文本文件中的结果。

time=print ("This is the time and date: " 
,datetime.datetime.now().strftime("%y-%m-%d-%H-%M"))
option_1=print("50p for 1 hour(S) stay")
with open("recipt.txt", "w") as recipt:
recipt.write("you time\n {}".format(time))
recipt.write("the time you stayed for and your payment\n
{}".format(option_1))
recipt.close()

提前致谢

最佳答案

print 函数返回None。您想要构建一个 str 对象而不是使用 print

time= "This is the time and date: " + datetime.datetime.now().strftime("%y-%m-%d-%H-%M")
option_1= "50p for 1 hour(S) stay"

关于python - 当我将变量写入文本文件时,为什么会得到 'none',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46309568/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com