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
Simplest way to do it is construct the anycodings_python string:,Is it possible to combine python output with anycodings_html html? I want to include the integer i in the anycodings_html note string (like the blue number) ,and inject the string in your snippet:,Can staticfiles in Django be served in production if they're located in non-english called directories?
Simplest way to do it is construct the anycodings_python 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
Many libraries support their own HTML output formatting, and this generally carries over to Jupyter Book outputs as well.,For example, the following cell has a long output, but will be scrollable in the book:,For example, the following cell uses Pandas to format cells based on their values:,The formatting of code outputs is highly configurable. Below we give examples of how to format particular outputs and even insert outputs into other locations of the document.
import numpy as np import pandas as pd np.random.seed(24) df = pd.DataFrame({ 'A': np.linspace(1, 10, 10) }) df = pd.concat([df, pd.DataFrame(np.random.randn(10, 4), columns = list('BCDE'))], axis = 1) df.iloc[3, 3] = np.nan df.iloc[0, 2] = np.nan def color_negative_red(val): "" " Takes a scalar and returns a string with the css property `'color: red'` for negative strings, black otherwise. "" " color = 'red' if val < 0 else 'black' return 'color: %s' % color def highlight_max(s): '' ' highlight the maximum in a Series yellow. '' ' is_max = s == s.max() return ['background-color: yellow' if v else '' for v in is_max ] df.style.\ applymap(color_negative_red).\ apply(highlight_max).\ set_table_attributes('style="font-size: 10px"')
{
"tags": [
"output_scroll",
]
}
for ii in range(40):
print(f "this is output line {ii}")
this is output line 0
this is output line 1
this is output line 2
this is output line 3
this is output line 4
this is output line 5
this is output line 6
this is output line 7
this is output line 8
this is output line 9
this is output line 10
this is output line 11
this is output line 12
this is output line 13
this is output line 14
this is output line 15
this is output line 16
this is output line 17
this is output line 18
this is output line 19
this is output line 20
this is output line 21
this is output line 22
this is output line 23
this is output line 24
this is output line 25
this is output line 26
this is output line 27
this is output line 28
this is output line 29
this is output line 30
this is output line 31
this is output line 32
this is output line 33
this is output line 34
this is output line 35
this is output line 36
this is output line 37
this is output line 38
this is output line 39
``
`{code-cell} ipython3
---
render:
image:
width: 200px
alt: fun-fish
classes: shadow bg-primary
figure:
caption: |
Hey everyone its **party** time!
name: fun-fish
---
from IPython.display import Image
Image("../images/fun-fish.png")
`
``
from IPython.display
import Image
Image("../images/fun-fish.png")
The Jupyter Notebook Format
{
"metadata": {
"signature": "hex-digest",
# used
for authenticating unsafe outputs on load "kernel_info": {
#
if kernel_info is defined,
its name field is required.
"name": "the name of the kernel"
},
"language_info": {
#
if language_info is defined,
its name field is required.
"name": "the programming language of the kernel",
"version": "the version of the language",
"codemirror_mode": "The name of the codemirror mode to use [optional]"
}
},
"nbformat": 4,
"nbformat_minor": 0,
"cells": [
# list of cell dictionaries, see below
],
}
{
"cell_type": "name",
"metadata": {},
"source": "single string or [list, of, strings]",
}
{
"cell_type": "markdown",
"metadata": {},
"source": ["some *markdown*"],
}
{
"cell_type": "code",
"execution_count": 1,
# integer or null "metadata": {
"collapsed": True,
# whether the output of the cell is collapsed "autoscroll": False,
# any of true,
false or "auto"
},
"source": ["some code"],
"outputs": [{
# list of output dicts(described below)
"output_type": "stream",
...
}],
}
{
"output_type": "stream",
"name": "stdout",
# or stderr "text": ["multiline stream text"],
}
{
"output_type": "display_data",
"data": {
"text/plain": ["multiline text data"],
"image/png": ["base64-encoded-png-data"],
"application/json": {
# JSON data is included as - is "json": "data",
},
},
"metadata": {
"image/png": {
"width": 640,
"height": 480,
},
},
}
Create different cell types and show/hide output in Jupyter,Create different cell types and show/hide output in Jupyter ,When you run cells of code the output is displayed immediately below the cell. In general this is convenient. The output is associated with the cell that produced it and remains a part of the notebook. So if you copy or move the notebook the output stays with the code.,However lots of output can make the notebook look cluttered and more difficult to move around. So there is an option available from the cell menu item to ‘toggle’ or ‘clear’ the output associated either with an individual cell or all cells in the notebook.
a = 2 b = 3.142
print(type(a))
print(type(b))
s = "Hello World"
print(type(s))
<class 'int'>
<class 'float'>
<class 'str'>
print("a =", a, "and b =", b) print(a + b) # addition print(a * b) # multiplication print(a - b) # subtraction print(a / b) # division print(b ** a) # exponentiation print(a % b) # modulus - returns the remainder print(2 * a % b) # modulus - returns the remainder
a = 2 and b = 3.142 5.1419999999999995 6.284 - 1.142 0.6365372374283896 9.872164 2.0 0.8580000000000001
print("a =", a, "and b =", b) print(a + 2 * b) # add a to two times b print(a + (2 * b)) # same thing but explicit about order of evaluation print((a + b) * 2) # add a and b and then multiply by two