在python的字符串中插入变量

2024-04-29 09:27:19 发布

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

我是python新手,我想知道如何将变量放在字符串中,以便在LCD 20x4显示器(2004A)中显示此类变量的内容。

代码如下:

with open("temperature.txt") as myfile:
currenttemp=myfile.readlines()

lcd_string("%(currenttemp)" ,LCD_LINE_1,2)

不幸的是,这将在LCD显示中打印"%(currenttemp)",而不是currenttemp变量值。


Tags: 字符串代码txt内容lcdaswithopen