Print a bold variable within st.write [no st.markdown/html]

Hi all,

I saw that recently streamlit added the possiblity to display bold font in st.buttons, st.write ecc ecc.
The problem is that is always fixed text. Example:

st.write("**bold** not bold")

Will give out the expected and correct output.
But, what if I’d like to display like a column’s name in bold (something that is stored in a variable)
Imagine the string is saved in the variable(type str): columnName
If I do, for example

st.write("Column name is " + **columnName**)
It’s not working because obviously it recognizes the ** as part of the varibale’s name.

How can I do in order to display the variable’s name in bold so?
Thank you in advance.


You can use f-strings (Python 3's f-Strings: An Improved String Formatting Syntax (Guide) – Real Python).

st.write(f"Column name is **{columnName}**")

1 Like