1
00:00:00,090 --> 00:00:03,120
So I come back to this lecture about Jupyter Notebook.

2
00:00:04,140 --> 00:00:10,050
I would say Jupyter Notebook is the most easy way to learn and to use Python, especially when you are

3
00:00:10,050 --> 00:00:10,620
beginning.

4
00:00:11,490 --> 00:00:16,320
So we just click on launch and is Jupyter Notebook Panel here?

5
00:00:17,160 --> 00:00:22,860
And what it does is it opens up your standard browser, which for me is Google Chrome.

6
00:00:23,850 --> 00:00:27,490
So here you just start in your personal directory.

7
00:00:27,780 --> 00:00:30,600
You can, of course, navigate here to different directories.

8
00:00:30,900 --> 00:00:36,000
But what I'm going to do is I will just create a new file right here in this directory.

9
00:00:37,110 --> 00:00:41,850
And here you can select the Python kernel that you want to use.

10
00:00:42,240 --> 00:00:47,520
So if you just have installed Anaconda, as I explained in the previous lecture, you will just have

11
00:00:47,670 --> 00:00:49,470
Python three here and nothing else.

12
00:00:49,860 --> 00:00:52,230
But maybe you have several installations of Python.

13
00:00:52,230 --> 00:00:54,660
So maybe here are more of these kernels.

14
00:00:55,380 --> 00:00:56,940
So I select Python three.

15
00:00:57,690 --> 00:01:05,489
It opens up a new tab and a new notebook, which we can save, and in this case, it will be saved right

16
00:01:05,489 --> 00:01:06,600
in this directory.

17
00:01:06,750 --> 00:01:08,670
And it's titled Untitled.

18
00:01:09,810 --> 00:01:11,280
Of course, you can also give it a name.

19
00:01:11,970 --> 00:01:15,720
And unlike in the previous lecture, I've used the command line tool.

20
00:01:15,720 --> 00:01:19,380
You can now go ahead and calculate just some basic stuff.

21
00:01:20,970 --> 00:01:23,610
Yeah, and eight plus three gives 11.

22
00:01:24,360 --> 00:01:27,030
Just the first comment here when I just press enter.

23
00:01:27,330 --> 00:01:29,670
It will not run the cell, but adds new lines.

24
00:01:29,670 --> 00:01:32,820
So to run the cell, I have to click Shift Plus enter.

25
00:01:33,720 --> 00:01:36,600
So what is special about Jupyter Notebook?

26
00:01:37,200 --> 00:01:38,920
Well, maybe you can see it already.

27
00:01:38,940 --> 00:01:41,130
We have something called cells.

28
00:01:41,670 --> 00:01:47,700
So here we have a first cell which contains this code and the output, and then we can just make or

29
00:01:47,700 --> 00:01:51,030
write and in the second cell or even add new cells.

30
00:01:51,360 --> 00:01:53,220
And here we can write additional stuff.

31
00:01:53,250 --> 00:01:55,470
For example, we could write is equal to one.

32
00:01:56,400 --> 00:02:02,550
Then we must, of course, run the cell and then we can write two times a plus one.

33
00:02:03,660 --> 00:02:06,750
But we can also write several commands in the same cell.

34
00:02:06,780 --> 00:02:09,210
We could, for example, then write three times a plus.

35
00:02:10,560 --> 00:02:16,800
And in this case, it just gives you the last output as the output of the cell.

36
00:02:18,030 --> 00:02:19,260
So what else can we do?

37
00:02:19,500 --> 00:02:27,930
We can delete this, of course, again, and then we can also redefine a in this cell.

38
00:02:28,080 --> 00:02:34,500
The bottom here and then we can click back in here and rerun the cell, and then it gives us a different

39
00:02:34,500 --> 00:02:35,010
result.

40
00:02:35,640 --> 00:02:42,030
So the important thing here is that it really matters in which order you run the cells.

41
00:02:42,030 --> 00:02:45,660
And this is very different from conventional program.

42
00:02:45,660 --> 00:02:52,170
For example, if you have some C code, for example, you just have one file and it runs from top to

43
00:02:52,170 --> 00:02:52,590
bottom.

44
00:02:53,250 --> 00:02:57,120
And here, if you have such a notebook, this is not necessarily the case.

45
00:02:57,750 --> 00:03:00,810
You can run these cells in any order you like.

46
00:03:01,680 --> 00:03:08,340
And for example, we can click here on kernel and we can restart and clear the output.

47
00:03:09,720 --> 00:03:14,430
So this will basically delete all of our results that we have gotten.

48
00:03:14,880 --> 00:03:22,140
And when I now just run this cell two times a plus one, it will give me an error because the variable

49
00:03:22,140 --> 00:03:28,260
A has not been defined yet, even though here a is defined in the previous cell.

50
00:03:28,830 --> 00:03:33,270
But we didn't run it yet, which you can see at the fact that this is here still empty.

51
00:03:34,290 --> 00:03:37,440
So now I run it, and now it gives us a results.

52
00:03:38,730 --> 00:03:44,700
So if you have a long code, it's very tedious to click in every cell and run every cell after another.

53
00:03:45,180 --> 00:03:49,670
So what you can do then, is you can focus on the click here, restart and run all.

54
00:03:50,760 --> 00:03:56,130
So that's sometimes a good idea to restart the kernel, to get rid of all of the old stuff and then

55
00:03:56,280 --> 00:03:57,240
run all cells.

56
00:03:58,470 --> 00:04:00,960
And then you see one to three four.

57
00:04:01,380 --> 00:04:03,360
All of these cells have been executed.

58
00:04:05,940 --> 00:04:13,890
So what additional information that I have to tell you is that these Jupyter notebooks are not the native

59
00:04:14,190 --> 00:04:24,000
Python files, which you can see at the fact that this this file here is labeled Untitled Todd IPY and

60
00:04:24,000 --> 00:04:28,620
B and a python file is labeled dot p y.

61
00:04:28,920 --> 00:04:30,210
So this is something else.

62
00:04:30,810 --> 00:04:33,180
It's a Jupyter notebook file.

63
00:04:33,540 --> 00:04:40,200
And the only difference between Jupyter Notebook File and the Python file is that a Python file is just

64
00:04:41,280 --> 00:04:48,510
a text consisting of lines of code, and the Jupyter Notebook file contains these individual cells,

65
00:04:48,510 --> 00:04:51,090
which then themselves contain Python code.

66
00:04:52,200 --> 00:05:00,900
So this makes it really easy to test stuff and to change variables and really do some quick programming.

67
00:05:00,900 --> 00:05:05,130
And this is why we are going to use this here in the majority of the course.

68
00:05:06,030 --> 00:05:11,940
But of course, if you want to write a very long code, or for example, if you want to run your code

69
00:05:11,940 --> 00:05:18,390
on the supercomputer cluster, then of course, it's probably better to use a conventional python file

70
00:05:18,750 --> 00:05:23,640
where you just have all of your lines of codes and you do not have these cells.

71
00:05:24,360 --> 00:05:27,930
But as I mentioned for learning, I think Jupyter Notebook is perfect.

