Jupyter Notebook Enhancements, Tips And Tricks

To Include Markdown in Your Code’s Output (Colors, Bold, etc.)

Just using print() often makes it difficult to have certain outputs standout in the sea of outputs.

https://stackoverflow.com/a/46934204/9201239 suggests a way to fix that and be able to include markdown in your output - here is a reduced version on the original post:

from IPython.display import Markdown, display
def printmd(string):
    display(Markdown(string))

printmd("**bold text**")

You can add color using html:

def printmd(string, color=None):
    colorstr = "<span style='color:{}'>{}</span>".format(color, string)
    display(Markdown(colorstr))

printmd("**bold and blue**", color="blue")

I currently started using this for printing scores - it stands out nicely from the rest of the noise.

12 Likes