I'm working on Jupyter Notebooks and I'd like to write the value of a Python string variable into a Markdown heading. I'm well aware that one can write, in a Markdown cell,
# Python
a = 'hello'
In a markdown cell, a is {{a}}
and this works for me, but I'm trying to do something like
# This is a heading with {{a}} in it
But the last attempt didn't work. I googled a little bit, but I couldn't find anything. Any help will be appreciated. Thanks in advance!
This works for me, but it is just a code cell; so it might not be the exact functionality you want...
from IPython.display import Markdown as md
a = 'hello'
md("# The data consists of {} observations. Bla, Bla, ....".format(a))
This is something you can do:
"This is a string with {{" + a + "}} in it"
I guess you're running into issues because '{}' is a reserved 'word' in python strings, and you can solve this issue by splitting the opening and closing brackets.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With