- author: Python and Pandas with Reuven Lerner
How to Use Markdown in Jupyter Notebooks
If you're familiar with Jupyter notebooks, you know that they're a powerful tool for writing and running code, and visualizing data all within a single environment. However, if you're just getting started with creating content in Jupyter notebooks, you may be wondering how to efficiently document your code for others to use and access. The answer is simple: by using markdown.
In this article, we'll walk you through the process of adding markdown to your Jupyter notebook pages. We'll also discuss why it's important to document your code and how markdown can help you do just that.
Why Document Your Code?
Documenting your code is important for several reasons, including:
- To help others understand your code, so they can use it appropriately and make changes if necessary
- To record and preserve your work, so that you can come back to it later and remember what you were doing
- To help you maintain your code, by making it easier for you to review and update your work
By taking the time to document your code effectively, you can help others and yourself in the long run.
What is Markdown?
Markdown is a simple syntax for formatting text that can be used in Jupyter notebooks and other online platforms. The idea behind markdown is that you can use plain text to create nice formatting, without needing to learn more complicated web development languages like HTML or CSS.
To start using markdown in Jupyter notebooks, go to the cell menu and switch the cell type to markdown. This will allow you to write text that is not interpreted as Python code. You can use the hash (#) symbol to create headlines and subheadings, and use asterisks (*) to format text as bold or italicized.
Markdown also supports the creation of lists. You can create numbered lists using Arabic numerals (1, 2, 3), or bullet-point lists using hyphens (-). You can even create sub-lists by indenting items in your list.
Additionally, you can add images to your markdown, and create hyperlinks to external sources.
How to Add Markdown to Jupyter Notebooks
Follow these steps to add markdown to your Jupyter notebooks:
- Go to the cell menu and switch the cell type to markdown.
- Use the hash (#) symbol to create headlines and subheadings, and use asterisks (*) to format text as bold or italicized.
- Create lists using Arabic numerals (1, 2, 3) for numbered lists or hyphens (-) for bullet-point lists. To create sub-lists, indent the items in your list.
- Add images by using the following syntax:
- Add hyperlinks to external sources using the following syntax:
- Once you've added your markdown content, you can execute the cell to see the formatted text.
Where to Learn More About Markdown
If you want to learn more about markdown, a great resource is the Markdown Guide. This website provides a comprehensive guide to basic markdown syntax, as well as information on more advanced features like tables, code blocks, and footnotes.
Hopefully, this article has given you a good introduction to using markdown in Jupyter notebooks. With this new knowledge, you can start documenting your code more effectively and create more engaging and informative Jupyter notebook pages.