简体   繁体   English

html输出中的整数(jupyter notebook)

[英]Integer in html output (jupyter notebook)

Is it possible to combine python output with html? 是否可以将python输出与html结合起来? I want to include the integer i in the note string (like the blue number) 我想在注释字符串中包含整数i(如蓝色数字) Jupyter笔记本

Simplest way to do it is construct the string: 最简单的方法是构造字符串:

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

and inject the string in your snippet: 并在您的代码段中注入字符串:

from IPython.core.display import display, HTML

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

This should work for you : 这应该适合你:

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

The output willl be: 输出将是:

Note 0
Note 1
Note 2
Note 3
Note 4
Note 5
Note 6
Note 7
Note 8
Note 9

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM