So I come back to this lecture about Jupyter Notebook.
I would say Jupyter Notebook is the most easy way to learn and to use Python, especially when you are
beginning.
So we just click on launch and is Jupyter Notebook Panel here?
And what it does is it opens up your standard browser, which for me is Google Chrome.
So here you just start in your personal directory.
You can, of course, navigate here to different directories.
But what I'm going to do is I will just create a new file right here in this directory.
And here you can select the Python kernel that you want to use.
So if you just have installed Anaconda, as I explained in the previous lecture, you will just have
Python three here and nothing else.
But maybe you have several installations of Python.
So maybe here are more of these kernels.
So I select Python three.
It opens up a new tab and a new notebook, which we can save, and in this case, it will be saved right
in this directory.
And it's titled Untitled.
Of course, you can also give it a name.
And unlike in the previous lecture, I've used the command line tool.
You can now go ahead and calculate just some basic stuff.
Yeah, and eight plus three gives 11.
Just the first comment here when I just press enter.
It will not run the cell, but adds new lines.
So to run the cell, I have to click Shift Plus enter.
So what is special about Jupyter Notebook?
Well, maybe you can see it already.
We have something called cells.
So here we have a first cell which contains this code and the output, and then we can just make or
write and in the second cell or even add new cells.
And here we can write additional stuff.
For example, we could write is equal to one.
Then we must, of course, run the cell and then we can write two times a plus one.
But we can also write several commands in the same cell.
We could, for example, then write three times a plus.
And in this case, it just gives you the last output as the output of the cell.
So what else can we do?
We can delete this, of course, again, and then we can also redefine a in this cell.
The bottom here and then we can click back in here and rerun the cell, and then it gives us a different
result.
So the important thing here is that it really matters in which order you run the cells.
And this is very different from conventional program.
For example, if you have some C code, for example, you just have one file and it runs from top to
bottom.
And here, if you have such a notebook, this is not necessarily the case.
You can run these cells in any order you like.
And for example, we can click here on kernel and we can restart and clear the output.
So this will basically delete all of our results that we have gotten.
And when I now just run this cell two times a plus one, it will give me an error because the variable
A has not been defined yet, even though here a is defined in the previous cell.
But we didn't run it yet, which you can see at the fact that this is here still empty.
So now I run it, and now it gives us a results.
So if you have a long code, it's very tedious to click in every cell and run every cell after another.
So what you can do then, is you can focus on the click here, restart and run all.
So that's sometimes a good idea to restart the kernel, to get rid of all of the old stuff and then
run all cells.
And then you see one to three four.
All of these cells have been executed.
So what additional information that I have to tell you is that these Jupyter notebooks are not the native
Python files, which you can see at the fact that this this file here is labeled Untitled Todd IPY and
B and a python file is labeled dot p y.
So this is something else.
It's a Jupyter notebook file.
And the only difference between Jupyter Notebook File and the Python file is that a Python file is just
a text consisting of lines of code, and the Jupyter Notebook file contains these individual cells,
which then themselves contain Python code.
So this makes it really easy to test stuff and to change variables and really do some quick programming.
And this is why we are going to use this here in the majority of the course.
But of course, if you want to write a very long code, or for example, if you want to run your code
on the supercomputer cluster, then of course, it's probably better to use a conventional python file
where you just have all of your lines of codes and you do not have these cells.
But as I mentioned for learning, I think Jupyter Notebook is perfect.