Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Eror函数中不支持的操作数类型_Python - Fatal编程技术网

Python Eror函数中不支持的操作数类型

Python Eror函数中不支持的操作数类型,python,Python,我正试图编写一个脚本来使用我的sensehat来测量房间中的温度/压力/湿度,当运行此脚本时,只有我的温度计函数返回此错误(它最后运行) prtemp是整数,不能使用+ 可以将int转换为字符串: print(str(prtemp) + "degC") 或者,最好使用格式化: print("{}degC".format(prtemp)) 或 或者使用f-stringsprint(f“{prtemp}degC”)谢谢!工作得很好。对不起,这个愚蠢的问题,我还在学习python。 print(s

我正试图编写一个脚本来使用我的sensehat来测量房间中的温度/压力/湿度,当运行此脚本时,只有我的温度计函数返回此错误(它最后运行)


prtemp
是整数,不能使用
+

可以将int转换为字符串:

print(str(prtemp) + "degC")
或者,最好使用格式化:

print("{}degC".format(prtemp))


或者使用f-strings
print(f“{prtemp}degC”)
谢谢!工作得很好。对不起,这个愚蠢的问题,我还在学习python。
print(str(prtemp) + "degC")
print("{}degC".format(prtemp))
print(f"{prtemp}degC"))