顯示帶有可選語法突出顯示的代碼塊。
(這是圍繞 st.markdown()
的便利包裝)
函數簽名
<code class="python">st.code(body, language="python")code>
參數 | 說明 |
---|---|
body (str) | 要顯示為代碼的字符串。 |
language (str) | 編寫代碼的語言,用於語法高亮。如果省略,代碼將沒有樣式。 |
示例
<code class="python">code = '''def hello(): print("Hello, Streamlit!")''' st.code(code, language='python')code>

相關用法
- Python Streamlit st.container用法及代碼示例
- Python Streamlit st.color_picker用法及代碼示例
- Python Streamlit st.columns用法及代碼示例
- Python Streamlit st.caption用法及代碼示例
- Python Streamlit st.cache用法及代碼示例
- Python Streamlit st.camera_input用法及代碼示例
- Python Streamlit st.checkbox用法及代碼示例
- Python Streamlit st.experimental_singleton.clear用法及代碼示例
- Python Streamlit st.bokeh_chart用法及代碼示例
- Python Streamlit st.text_input用法及代碼示例
- Python Streamlit st.area_chart用法及代碼示例
- Python Streamlit st.title用法及代碼示例
- Python Streamlit st.experimental_singleton用法及代碼示例
- Python Streamlit st.empty用法及代碼示例
- Python Streamlit st.error用法及代碼示例
- Python Streamlit st.video用法及代碼示例
- Python Streamlit st.vega_lite_chart用法及代碼示例
- Python Streamlit st.slider用法及代碼示例
- Python Streamlit st.header用法及代碼示例
- Python Streamlit st.form_submit_button用法及代碼示例
- Python Streamlit st.form用法及代碼示例
- Python Streamlit st.plotly_chart用法及代碼示例
- Python Streamlit st.bar_chart用法及代碼示例
- Python Streamlit st.experimental_memo.clear用法及代碼示例
- Python Streamlit st.warning用法及代碼示例
注:本文由純淨天空篩選整理自streamlit.io大神的英文原創作品 st.code。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。