2024-04-29 09:27:19 发布
网友
我是python新手,我想知道如何将变量放在字符串中,以便在LCD 20x4显示器(2004A)中显示此类变量的内容。
代码如下:
with open("temperature.txt") as myfile: currenttemp=myfile.readlines() lcd_string("%(currenttemp)" ,LCD_LINE_1,2)
不幸的是,这将在LCD显示中打印"%(currenttemp)",而不是currenttemp变量值。
"%(currenttemp)"
Python中的字符串格式示例:
代码:
a = "one line file" print("this file contains: %s" %a)
输出:
this file contains: one line file
有关各种字符串格式技术的性能比较,请参见:Python string formatting: % vs. .format
Python中的字符串格式示例:
代码:
输出:
有关各种字符串格式技术的性能比较,请参见:Python string formatting: % vs. .format
相关问题 更多 >
编程相关推荐