【问题标题】:STREAMLIT: How to print the output of a functionSTREAMLIT:如何打印函数的输出
【发布时间】:2021-12-29 21:13:35
【问题描述】:

我有这个功能:

def hello (name):
    return ('Hello ', name)

first_variable = hello('Maya')
st.text(first_variable)

我想在我的网络应用中看到“Hello Maya”,但我得到:“无”

我该怎么办?

【问题讨论】:

  • 你将一个元组传递给st.text;也许你的意思是传递一个字符串?

标签: function data-science streamlit


【解决方案1】:

您将返回一个元组,其第一个索引为 'Hello',第二个索引为 name。如果您在返回时删除括号(在 Python 中创建 Tuple 类型)并将其替换为字符串连接,它应该返回 'Hello Maya'

def hello(name: str) -> str:
    return 'Hello ' + name

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-21
    • 1970-01-01
    • 2020-02-11
    • 2018-10-09
    • 2016-10-13
    • 1970-01-01
    • 2010-09-18
    相关资源
    最近更新 更多