1
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 ?

3
  • 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. Commented Jul 2, 2020 at 6:29
  • @JanChristophTerasa Thanks, but is there any way to get both being shown? Commented Jul 2, 2020 at 6:31
  • 1
    print them, or seperate into two blocks, or put both expressions on a single line (which will return a tuple). Commented Jul 2, 2020 at 6:32

2 Answers 2

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"
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.