Question Details

No question body available.

Tags

python streamlit conditional-operator

Answers (1)

June 26, 2026 Score: 1 Rep: 153,348 Quality: Medium Completeness: 60%

The A if B else C expression returns A if B is "truthy", else it returns C. Streamlit is printing the result of that expression (because Streamlit sees that the entire line is an expression and assumes you want to display it), which since it is a function that does not return a value, is None.

The if/else statements would be more appropriate here since you don't really care about the return value of the function:

if name:
    main(name)
else:
    main()  

However, this should be handled (in my opinion) by the function, not the caller. You can do that by using None as the default value instead of the string:

def main(name=None):
    if name is None:
        name = "World"
    st.write(f"Hello {name}!")

or, if this is the only place you use name:

def main(name=None):
    st.write(f"Hello {name or 'World'}!")

then you can just call:

main(name)

and if name is None then it will use "World" in the string.