Last answered:

30 Nov 2023

Posted on:

29 Nov 2023

0

Resolved: Restarting Kernel & re-runnung the whole notebook

Why do we restart Kernal and re-excute the codes.....what is the importance of this step?

1 answers ( 1 marked as helpful)
Instructor
Posted on:

30 Nov 2023

0

Hi Asmaa!

Thanks for reaching out!

Restarting the kernel in Jupyter Notebook is crucial for ensuring a clear and isolated execution of code cells.

When you run code cells in a Jupyter Notebook, each executed cell can modify the program's state. These changes remain in memory and can influence the execution of subsequent cells.

For example, if you define a variable in one cell and change its value in another, this new value persists in the notebook's memory. If you rerun the second cell without rerunning the first one, it will use the modified value, which might not be what you initially intended.

Restarting the kernel wipes the memory clean. This means it removes all the variables, functions, and data that were loaded or defined in your session. After a restart, the notebook has no memory of what was executed before.

In essence, restarting the kernel allows you to simulate a fresh, first-time execution of your code, ensuring that each cell in your notebook can run independently and in the correct order. This is a key practice for writing reliable and reproducible code. This is why we demonstrate it in the current lesson.

Hope this helps.

Best,

Ivan

Submit an answer