In this tutorial, we will learn how to add text to your Streamlit application and explore the different commands available for displaying text and formatting.

Main Functions for Displaying Text

Streamlit offers several simple and useful functions for displaying text, from basic strings to complex mathematical expressions. Let's explore some of them:

st.write()

This is a versatile function used to add almost any type of element to your application, such as strings, charts (Matplotlib, Plotly, Altair), dataframes, Keras models, and much more.

Example:

import streamlit as st

st.write("Hello! Let's learn together how to build an application in Streamlit.")

st.title()

Adds the main title of the application.

Example:

st.title("Application Title")

st.header()

Defines the main heading of a section.

Example:

st.header("This is the section header")

st.subheader()

Defines a subsection title.

Example:

st.subheader("This is the subsection title")

st.markdown()

Allows writing text using Markdown language for advanced formatting.

Example:

st.markdown("**Bold text**, *italic text*, and [a link](https://streamlit.io).")

st.caption()

Adds a caption or auxiliary text.

Example:

st.caption("Explanatory caption for a chart or section.")

st.code()

Displays formatted code blocks.

Example:

st.code("""
def add(a, b):
    return a + b
print(add(2, 3))
""")

st.latex()

Displays formatted mathematical expressions using LaTeX.

Example:

st.latex(r'''
E = mc^2
''')

With these commands, you can efficiently display text and formatted content in your Streamlit applications!