Something to point out is that when your
function doesn't have a return statement, save, execute,
it implicitly returns a None object.
None is a specific object
in Python, which means nothing.
It's not an integer, it's not
a float, it's not a string.
It's just None.
It means nothing.
So Python, what it does is, if
it doesn't find the return statement on
the background, it does this return None.
So if you execute that oops, an indentation error.
That's a good thing. So you see that all this block here
has to be the same level of indentation.
If you indented four lines here, you have
to indent four lines in here, too.
So indentation has to be consistent.
That looks right.
So we got the same output None here and None there.
Some people do this mistake.
Instead of returning, they use print.
Instead of using return, they use a print
function, the_mean, which works half the way.
So it still returns the value,
and it also returns None.
So what's going on here is that when you call
the function here, Python will execute all these lines.
So it calculates the_mean.
Then it goes to the next line.
So line by line, it will print the_mean.
So it will print out the_mean in here,
and then it will look for a return statement.
It doesn't find it, so it will return None.
The problem with this is that if you try to do
some other operations with your mean value, let's say mymean
is equal to the mean function 0, 3, and 4, okay?
And I want to print out mymean + 10.
So I would expect that this would give me the
value of, 7 is the sum divided by three.
So 2 point something plus 10, 12 point something.
But let's see what this will give me.
[No audio]
So this will give me a TypeError
instead. It tried to add the none type, which is None.
So this is a none type.
That's the type of this value.
It's trying to add that to ten.
So mymean is None, because it returns none.
And the interpreter will try to add up that to 10.
That's not possible.
So that's why you shouldn't use print.
If I replace that with return instead, remove the
parentheses, save, execute, that will give me 12.3.
That is the average plus ten.
However, this doesn't mean you cannot
use print in your functions.
You can actually do that.
Let's say you just want to print some information.
[Author typing]
started, Function started!, and execute that.
So you get the output of print in
here, and then Python returns the mean.
So you get the mean, you store it
in here, the output of your function.
But the value of the function is
always what you return in here.
So if you see that it,
[Author typing]
so always use return in your
functions, unless you have a very special reason to do so.
[Outro sound]