Akram Hijjawi
Akram Hijjawi

Reputation: 3

Why is Jupyter not showing all the results as expected?

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

Upvotes: 0

Views: 602

Answers (3)

RezaShojaeivand
RezaShojaeivand

Reputation: 24

Python starts complying after the print command, in Jupyter 4 also compiles like 3 and you have got " 3 and 4 ", but if you run this code through the cmd console or Linux terminal, your output will be just 3, because the compiler didn't find the python command for 4.

Upvotes: 0

Jeanot Zubler
Jeanot Zubler

Reputation: 1385

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)

Upvotes: 1

Ogün Birinci
Ogün Birinci

Reputation: 728

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.

Upvotes: 1

Related Questions