0
ls = [16, 81, 23, 74, 91, 612, 33, 812]

ls[2:6:3] #Starting from index 2 till index 5 and skip the next 2 indices
ls[::-1]  # Reverse list is printed

Only 2nd line i.e. ls[::-1] is executed. What am I doing wrong ?

Dimenein
  • 281
  • 2
  • 5
  • 1
    Jupyter will only output the result of the last expression in a block. As you can see, all statements are executed. The second statement is executed, but the result is discarded, since it is not assigned to anything. – Jan Christoph Terasa Jul 02 '20 at 06:29
  • @JanChristophTerasa Thanks, but is there any way to get both being shown? – Dimenein Jul 02 '20 at 06:31
  • 1
    `print` them, or seperate into two blocks, or put both expressions on a single line (which will return a tuple). – Jan Christoph Terasa Jul 02 '20 at 06:32

2 Answers2

1

It does execute all the lines, it only output the last one by default. If you want to see all the steps, you can print the result you want to see.

This answer also gives an alternative by asking jupyter to show all output systematically by adding

from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
ShadowMitia
  • 2,411
  • 1
  • 19
  • 24
0

Please restart your jupyter-notebook again and also refresh jupyter. Hope its helpful..

Lovelesh
  • 1
  • 1