This is because there is a tab at the beginning of each line of your triple-quoted string, due to it being nested inside of with tab1:
. Two solutions:
- Don’t indent the code inside the triple-quote:
with tab1:
st.code('''
import streamlit as st
st.write("Hello, Streamlit!")
st.write("Hello, Streamlit!")
''',
'python')
Option 2: from textwrap import dedent
with tab1:
st.code(
dedent('''
import streamlit as st
st.write("Hello, Streamlit!")
st.write("Hello, Streamlit!")
'''),
"python",
)