There is a unique thing that we can do with functions that we haven't seen before, and they're called
doc strings.
Let me show you what I mean.
If I had a function here and we'll just call it test and test, let's say receives a parameter that
is a and in here it's going to print a what?
A useless.
Completely useless.
Function.
Now, if I run this well, nothing's going to happen because I have to call test and then say, well,
exclamation marks.
And you see that our function works.
But we can actually with functions in Python use something called doc strings and it looks something
like this.
You do single code, single code, single code.
So three of them.
And then at the bottom once again, single code, single code, single code.
So the beginning of the function like this and in here I can add some info about the function.
For example, this function tests and prints.
Per am a.
Now, here's the interesting part.
If I run tests here and I do brackets, look at that.
My editor tells me info.
This function tests and prints per am a this is called a doc string.
And what it allows us to do is to actually comment inside of our functions in a way that if another
person, let's say, is using the test function, they can actually let say in the future, when we
write large applications where it's not just ten lines of code or maybe we have different files instead
of just finding what test does.
As I'm typing it, it's going to tell me, hey, test is going to return or print param a so I find
out information about this and if we ever use something like length, for example, and run this, you
see that this gives us information about the function by using doc strings, but it comes built in with
Python.
Another way to view this.
Mind you, when we talk about devolve payer environments, our editors are going to do this automatically.
But there's a few other ways that we can actually read this.
For example, I can do the help function, which we haven't seen before, which comes prebuilt with
Python.
And we don't want to call the function.
I just want to call help on test if I run this.
Look at that.
I get test info.
This function tests and prints parameters so we can use help to find out what a function does, which
is really, really useful.
One other way to do this is to use what we call a magic method or a dunder method, which again we'll
get into later on in the course.
I do double underscore then.
I do, doc.
And then double underscore like this if I click run.
Well, we have to print something here, so let's print.
Click Run and look at that.
I get the same thing.
So these dog strings are really, really useful to add comments and definitions to your functions so
that when other people on your, let's say, team or coworkers come across your function that you created,
they're able to understand what it does right away without searching through your python files or multiple
files.
Very useful feature.