【发布时间】:2020-05-25 05:04:09
【问题描述】:
我的 streamlit 应用程序中出现下一个错误:
我的错误是:
TypeError: +: 'int' 和 'str' 的操作数类型不受支持
我的代码是:
import streamlit as st
if st.button("SUBMIT"):
calculation = 23*2
string = "Hello"
result= (calculation + str(string))
st.success(result)
【问题讨论】:
-
calculation是一个整数。在 python 中,你不能直接将整数与字符串相加。使用str(calculation)代替 -
再次阅读错误信息。您尝试添加一个整数和一个字符串。
calculation是46,这是一个整数。str(string))是一个字符串(我不确定你为什么要将字符串"Hello"再次转换为字符串)。如果您问“为什么没有自动转换”,请回答以下问题。您希望"1" + 2的结果是什么?为什么?
标签: python machine-learning streamlit