1
00:00:02,480 --> 00:00:02,719
Hi.

2
00:00:02,719 --> 00:00:03,469
Welcome back.

3
00:00:03,500 --> 00:00:07,010
In this video, you will learn how to use dog strings.

4
00:00:09,060 --> 00:00:10,920
So what are those strings?

5
00:00:10,950 --> 00:00:14,580
Well, you have heard me mention them here and there.

6
00:00:16,010 --> 00:00:19,280
But we never explained exactly what they are.

7
00:00:19,610 --> 00:00:23,990
So you assume that when we do something like help.

8
00:00:27,320 --> 00:00:29,090
And you check the help.

9
00:00:30,320 --> 00:00:35,090
Documentation of a function such as input or prints or Len.

10
00:00:35,330 --> 00:00:36,500
Let's try, Len.

11
00:00:41,040 --> 00:00:43,740
You get this documentation.

12
00:00:44,070 --> 00:00:48,690
This is actually called the docstring of that function.

13
00:00:50,960 --> 00:00:53,130
So if you are on charm.

14
00:00:54,970 --> 00:00:58,990
You can actually see where this docstring is written.

15
00:00:58,990 --> 00:01:09,790
So in a python file just writes len and then right click over it and go to go to then to implementation.

16
00:01:10,630 --> 00:01:16,040
That will take you at the file where Len is written.

17
00:01:16,060 --> 00:01:21,550
Now this is a fake function, but the string is.

18
00:01:23,090 --> 00:01:24,590
The actual docstring.

19
00:01:24,620 --> 00:01:29,510
So this docstring is the one displayed in here as well.

20
00:01:32,120 --> 00:01:40,580
So when you do help lend, for example, then the help function generates these automatic text help

21
00:01:40,580 --> 00:01:47,060
on built in functional and in module bulletins, and it also generates the structure of the function

22
00:01:47,330 --> 00:01:52,940
and then it extracts the docstring from the place where the function is defined.

23
00:01:53,390 --> 00:01:54,980
In this case it is here.

24
00:01:57,110 --> 00:01:59,030
So we can do the same.

25
00:02:03,140 --> 00:02:05,060
For our own functions.

26
00:02:06,890 --> 00:02:12,110
So dog strings are written in the first line.

27
00:02:13,470 --> 00:02:18,350
And use triple quotes from both sides of the strings.

28
00:02:18,360 --> 00:02:26,070
So then you write the description of the function so that if your function is later used by someone

29
00:02:26,070 --> 00:02:33,420
else or by you, they can use the help function and see the help documentation, the docstring of the

30
00:02:33,420 --> 00:02:34,080
function.

31
00:02:35,950 --> 00:02:37,750
So what can you write here?

32
00:02:37,780 --> 00:02:41,040
Well, we can learn from these functions here.

33
00:02:41,050 --> 00:02:47,770
So the land function says that the return, the number of items in a container, that's what the land

34
00:02:47,770 --> 00:02:48,970
function does.

35
00:02:50,260 --> 00:02:56,950
So it calculates the number of items in the list or string or other sequence types of objects.

36
00:03:00,230 --> 00:03:02,240
And there are other functions as well.

37
00:03:02,240 --> 00:03:04,100
So that's the input function.

38
00:03:05,340 --> 00:03:10,080
This has more description and when there is more text you want to.

39
00:03:11,400 --> 00:03:17,670
Put the text between the triple quotes in separate lines, as you see here.

40
00:03:19,890 --> 00:03:20,970
In our case.

41
00:03:22,140 --> 00:03:24,480
So make a space and write something.

42
00:03:29,320 --> 00:03:35,740
Reads a text file and return the list of.

43
00:03:37,070 --> 00:03:45,470
So since this is getting too long, I think we can split it and we can write the neck the rest in here.

44
00:03:46,070 --> 00:03:51,980
So read the text file and returns the list of to do items.

45
00:03:54,140 --> 00:03:55,460
So that should do it.

46
00:03:57,100 --> 00:03:59,590
So it's the same format as this one here.

47
00:04:02,330 --> 00:04:04,970
How is this docstring useful now?

48
00:04:06,630 --> 00:04:14,610
Well, currently it is not very useful given the structure of of our program, but you'll see later

49
00:04:14,610 --> 00:04:22,290
on that you can create multiple Python files for one program and then these files can interact with

50
00:04:22,290 --> 00:04:22,950
each other.

51
00:04:24,630 --> 00:04:31,500
Then you might want to access the help documentation of a function from another file.

52
00:04:32,530 --> 00:04:39,190
And so then it becomes helpful to have this docstring as an experiment.

53
00:04:39,190 --> 00:04:43,540
You could also try the health function in here and say get to dos.

54
00:04:44,380 --> 00:04:51,190
And so you want to print out the output of help here in the command line in the python console.

55
00:04:51,190 --> 00:04:56,770
You don't have to use print, as I have mentioned before, for functions, for variables.

56
00:04:56,770 --> 00:05:00,760
You just call the variable or the function and you just get the output.

57
00:05:00,760 --> 00:05:04,930
But here you want to print the output of help.

58
00:05:05,170 --> 00:05:09,640
So let's run the script and that's what we get.

59
00:05:09,640 --> 00:05:17,320
So that's the request to enter it to do, which is executed by this line.

60
00:05:17,320 --> 00:05:18,670
So that's the output of that.

61
00:05:18,670 --> 00:05:27,220
But before this we get this docstring printed out by this help file.

62
00:05:27,220 --> 00:05:29,170
So that's the help documentation.

63
00:05:29,350 --> 00:05:32,440
As you see help and function get to do is module main.

64
00:05:32,440 --> 00:05:39,130
This is automatically generated by the help function and then we have a representation of the to dos

65
00:05:39,130 --> 00:05:40,060
function.

66
00:05:40,930 --> 00:05:44,530
So it shows what's file, what arguments it gets.

67
00:05:45,960 --> 00:05:48,840
It shows that this has a default value.

68
00:05:51,190 --> 00:05:54,820
And then it shows the docstring of the function in here.

69
00:05:56,270 --> 00:05:58,940
So read the text file and return to the list of To-Do items.

70
00:05:58,980 --> 00:06:00,770
So now if anybody else.

71
00:06:01,680 --> 00:06:08,040
Uses your function, they can read what the function does by using the help function.

72
00:06:09,730 --> 00:06:12,190
And the docstring you write is important.

73
00:06:15,350 --> 00:06:16,790
So let me close that.

74
00:06:17,870 --> 00:06:19,400
Delete that line.

75
00:06:21,340 --> 00:06:27,430
So that was one use case of the docstring when someone else uses your functions or you use your your

76
00:06:27,430 --> 00:06:29,170
functions through the help file.

77
00:06:29,200 --> 00:06:34,030
Another use is of course for you directly so when you write.

78
00:06:35,130 --> 00:06:37,080
And then then read your code.

79
00:06:37,080 --> 00:06:40,560
You look at your code later on and you see these functions.

80
00:06:40,560 --> 00:06:43,710
You can just look at the docstring, you can read what it does.

81
00:06:43,710 --> 00:06:49,740
So that will tell you what this function does so that you don't have to look at the code.

82
00:06:51,060 --> 00:06:52,710
So descriptions are good.

83
00:06:52,740 --> 00:06:55,950
Let's write a f string for this function as well.

84
00:06:55,950 --> 00:06:59,100
So three double quotes a space.

85
00:07:02,500 --> 00:07:11,890
Right to do item list in the text file.

86
00:07:13,000 --> 00:07:14,860
So that should be enough.

87
00:07:17,220 --> 00:07:18,780
That's a bold docstring.

88
00:07:18,780 --> 00:07:20,360
So it is.

89
00:07:20,490 --> 00:07:24,060
It is recommended to use docstring for every function.

90
00:07:24,960 --> 00:07:31,290
Some people just don't use them, especially when you have simple very simple functions.

91
00:07:32,100 --> 00:07:35,910
But the general recommendation is to use doc strings.

92
00:07:36,690 --> 00:07:38,160
So thanks a lot for following this.

93
00:07:38,160 --> 00:07:40,260
I hope it makes sense and see you later.

