[No audio]
To calculate the average of these grades, we want to see
if a list type has some sort of mean or average
method that allows us to get the average of its values.
For that, we go to check with dir(list).
So list is the name that represents all lists.
So that is a type, and this is an
instance of that type of list type, dir(list).
And let's have a quick look here.
Do we have a mean or average method?
I don't think so.
So there's no method of the list type to
allow us to calculate the average of list values.
However, that doesn't mean there adoesn't exist
A mean method in Python to do that.
mean or average is not a method,
but it can be a function.
You remember the print function.
So print like that, you see that print
doesn't need the dot notation to be used.
Like, for example, the upper method did
need a dot notation because upper is
a method attached to the hello type.
And print is a function.
It's an independent function that
works with many types.
Not only strings, not only integers, floats,
you can print anything with print.
That's why it's not attached to a specific type.
So where do we see a complete
list of functions that we can use?
You can do that using dir(__builtins__).
And that is
[No audio]
a complete list of
what you can use built in functions.
So let me see for a mean function
or an average function. No, it's not there.
Okay, but there is a sum function.
So what we can do is let's say mysum,
don't use sum as a variable name because
you can see that sum is a reserved keyword.
So sum(student_grades) that will give
us the sum of these three numbers.
And then we want to count how
many items there are in that list.
So do we have a count something there?
Maybe not.
Well, I know there's no count method, but we have
this len, which means, you can check what it means.
[Author typing]
So return the number of items in a container.
So a list is also referred to as a container.
Let's say length equals to len(student_grade).
And then finally we can get the mean, which is my
mysum divided by length, and print out the mean. Save,
[No audio]
and that is the mean value of all those three numbers.
[Outro sound]