0
  import streamlit as st
  statename = "some state name"
  d = 2000
  
  st.markdown("""
    #### "<span style="color:blue">{temp1}</span> has made {temp} calls".format(temp1 = statename, temp = str(d))    
  """,  unsafe_allow_html=True)

Here the .format is now working. The whole line is treated as a string.

Output: output

Any idea how to fix this?

1 Answer 1

2

can you try "f" other than .format as following?:

f"""
  #### "<span style="color:blue">{temp1}</span> has made {str(d)} calls"  
"""

see the output below:

  #### "<span style="color:blue">some state name</span> has made 2000 calls"

using .format:

"""
  #### "<span style="color:blue">{}</span> has made {} calls"   
""".format(statename,str(d))

or

"""
  #### "<span style="color:blue">{temp1}</span> has made {temp} calls"   
""".format(temp1=statename,temp=str(d))
Sign up to request clarification or add additional context in comments.

2 Comments

It worked, but why?
I think .format should be outside of """ as edited. This should also work when using .format.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.