Search⌘ K
AI Features

Display Code with Streamlit

Discover how to effectively display code in your Streamlit applications. Learn to use the st.code method to show code blocks without running them and the st.echo method to execute and display code simultaneously. This lesson helps you present code clearly for users or demonstrate functional implementations within your app.

We can display code in two ways.

Display code without execution

To display a block of code, we use the st.code() method:

Python 3.5
import streamlit as st
st.markdown("## Display code without execution")
code = '''st.audio("https://bit.ly/rainaws3")'''
st.code(code, language='python')
...