Hi.
Welcome back.
In this video, you will learn how to use dog strings.
So what are those strings?
Well, you have heard me mention them here and there.
But we never explained exactly what they are.
So you assume that when we do something like help.
And you check the help.
Documentation of a function such as input or prints or Len.
Let's try, Len.
You get this documentation.
This is actually called the docstring of that function.
So if you are on charm.
You can actually see where this docstring is written.
So in a python file just writes len and then right click over it and go to go to then to implementation.
That will take you at the file where Len is written.
Now this is a fake function, but the string is.
The actual docstring.
So this docstring is the one displayed in here as well.
So when you do help lend, for example, then the help function generates these automatic text help
on built in functional and in module bulletins, and it also generates the structure of the function
and then it extracts the docstring from the place where the function is defined.
In this case it is here.
So we can do the same.
For our own functions.
So dog strings are written in the first line.
And use triple quotes from both sides of the strings.
So then you write the description of the function so that if your function is later used by someone
else or by you, they can use the help function and see the help documentation, the docstring of the
function.
So what can you write here?
Well, we can learn from these functions here.
So the land function says that the return, the number of items in a container, that's what the land
function does.
So it calculates the number of items in the list or string or other sequence types of objects.
And there are other functions as well.
So that's the input function.
This has more description and when there is more text you want to.
Put the text between the triple quotes in separate lines, as you see here.
In our case.
So make a space and write something.
Reads a text file and return the list of.
So since this is getting too long, I think we can split it and we can write the neck the rest in here.
So read the text file and returns the list of to do items.
So that should do it.
So it's the same format as this one here.
How is this docstring useful now?
Well, currently it is not very useful given the structure of of our program, but you'll see later
on that you can create multiple Python files for one program and then these files can interact with
each other.
Then you might want to access the help documentation of a function from another file.
And so then it becomes helpful to have this docstring as an experiment.
You could also try the health function in here and say get to dos.
And so you want to print out the output of help here in the command line in the python console.
You don't have to use print, as I have mentioned before, for functions, for variables.
You just call the variable or the function and you just get the output.
But here you want to print the output of help.
So let's run the script and that's what we get.
So that's the request to enter it to do, which is executed by this line.
So that's the output of that.
But before this we get this docstring printed out by this help file.
So that's the help documentation.
As you see help and function get to do is module main.
This is automatically generated by the help function and then we have a representation of the to dos
function.
So it shows what's file, what arguments it gets.
It shows that this has a default value.
And then it shows the docstring of the function in here.
So read the text file and return to the list of To-Do items.
So now if anybody else.
Uses your function, they can read what the function does by using the help function.
And the docstring you write is important.
So let me close that.
Delete that line.
So that was one use case of the docstring when someone else uses your functions or you use your your
functions through the help file.
Another use is of course for you directly so when you write.
And then then read your code.
You look at your code later on and you see these functions.
You can just look at the docstring, you can read what it does.
So that will tell you what this function does so that you don't have to look at the code.
So descriptions are good.
Let's write a f string for this function as well.
So three double quotes a space.
Right to do item list in the text file.
So that should be enough.
That's a bold docstring.
So it is.
It is recommended to use docstring for every function.
Some people just don't use them, especially when you have simple very simple functions.
But the general recommendation is to use doc strings.
So thanks a lot for following this.
I hope it makes sense and see you later.