HTML输出中的整数(Jupyter笔记本)

4

是否可能将Python的输出与HTML相结合?我想在注释字符串中包含整数i(就像蓝色数字一样)Jupyter notebook


3
请将代码贴在这里,而不是以图片形式呈现。 - Inder
2个回答

2
这应该适合您的需求:

最初的回答:

from IPython.core.display import display,HTML
for i in range(10):
    display(HTML('<h2>Note %s</h2> '%i))

最终输出结果为:
Note 0
Note 1
Note 2
Note 3
Note 4
Note 5
Note 6
Note 7
Note 8
Note 9

2

Simplest way to do it is construct the string:

htmlOutput = '<h2>Note: '+ str(i) +'</h2>'

将字符串注入您的片段中:

并在您的代码片段中插入该字符串:

。最初的回答。
from IPython.core.display import display, HTML

for i in range(10):
  htmlOutput = '<h2>Note: '+ str(i) +'</h2>'
  display(HTML(htmlOutput))


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接