Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have python code and markdown in one cell

Can jupyter notebook support inline python code (arthritic calculations, or plot a figure) in markdown cell, or verse visa. Have both python code and markdown in one cell.

like image 283
Tmx Avatar asked Feb 12 '16 01:02

Tmx


People also ask

How do you include code blocks within markdown cells?

Just follow the same steps each time. Press Esc key, type m for markdown cell, press Enter key. The cursor is now in the markdown cell waiting for instructions. Type your code or paste a code block.

What is a markdown cell in Python?

Markdown cell displays text which can be formatted using markdown language. In order to enter a text which should not be treated as code by Notebook server, it must be first converted as markdown cell either from cell menu or by using keyboard shortcut M while in command mode.


2 Answers

from IPython.display import display, Markdown
display(Markdown("# Hello World!"))
like image 185
Kevin Zhu Avatar answered Sep 27 '22 03:09

Kevin Zhu


I don't think that's possible but there is an extension that you could use: https://github.com/ipython-contrib/IPython-notebook-extensions/wiki/python-markdown

That way you can display the result (and only the result) of a python statement inside a markdown cell.

like image 33
MSeifert Avatar answered Sep 26 '22 03:09

MSeifert