Why is Jupyter not showing all the results as expected?
Question:
I am trying the following:
In [] : 1
2
print(3)
4
and getting the following:
3
Out[] : 4
why not get:
1
2
3
4
Answers:
Jupyter just shows the last result default. You can set it like this
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
After run this code, you can get all of the outputs.
Jupyter normally just shows the result from the last expression in the Output. In your case, that is 4
. Jupyter also shows everything that is printed to the console. In your case that is 3
.
Your 1
and 2
statements do nothing, so they are not shown anywhere. If you want to show the numbers 1-4 in the output, I would suggest you print each of them, and do not rely on the return value of Jupyter.
print(1)
print(2)
print(3)
print(4)
or even more concise:
for i in range(1,5): # start at one, stop before 5
print(i)
I am trying the following:
In [] : 1
2
print(3)
4
and getting the following:
3
Out[] : 4
why not get:
1
2
3
4
Jupyter just shows the last result default. You can set it like this
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
After run this code, you can get all of the outputs.
Jupyter normally just shows the result from the last expression in the Output. In your case, that is 4
. Jupyter also shows everything that is printed to the console. In your case that is 3
.
Your 1
and 2
statements do nothing, so they are not shown anywhere. If you want to show the numbers 1-4 in the output, I would suggest you print each of them, and do not rely on the return value of Jupyter.
print(1)
print(2)
print(3)
print(4)
or even more concise:
for i in range(1,5): # start at one, stop before 5
print(i)