Sometimes things get really messy and you want to clear the output from a cell or a bunch of cells.
select the cells you want to clear the outpu from and go to this menu:
Cell --> Current Outputs --> Clear
or you can clear all of the output cells:
Cell --> All Output --> Clear
or you can restart the kernel and clear all of the output cells:
Kernel --> Restart & Clear Output
The notebook runs cells in the order that you run them. I can hear you saying Duh! but they are necessarily in linear order, but we can edit them and run them in any order we please. This is both a cool feature and a curse.
run the next few cells of code in order:
In [ ]:
trouble = 0
In [ ]:
trouble = trouble * 10
In [ ]:
trouble
my output the first time is:
now run the cell below:
In [ ]:
trouble = 42
now go back up and run the two cells right before you recorded your output for the first time:
notice the numbers in the Out [ ]:
after the the code you just reran -- the number is different!
And so is your output!
my output the second time is:
Remember -- this is both a cool feature and a curse.
I find that if things go super-duper sideways, that restarting and running all the cells helps since this runs them all in linear/sequential order.
you can restart the kernel and run all of the notebook:
Kernel --> Restart & Run All
Another quirk is that each code cell can only have one output (one In[ ]:
, one Out[ ]:
)
to illustrate, assign these 2 variables
In [ ]:
value = 42
name = "Hal"
by running a code cell with the name, the value is sent to Out[ ]:
In [ ]:
value
see the difference when you call the print()
function and pass it the identifier?
In [ ]:
print(value)
again...
In [ ]:
name
In [ ]:
print(name)
it gets worse when you have multiple things in a cell.
The output of a code cell can only be one thing! In this case we only see the output of the last thing in the Out[ ]:
In [ ]:
value
name
In [ ]:
name
value
but you can print multiple things...
In [ ]:
print(value)
print(name)
notice that this one doesn't have an Out[ ]:
since we used print.
this will get you at some point, so watch out for it!