All right, in the previous lecture I showed you the syntax of a function definition
and the syntax of how to call a function so this is the basic
representation of a function, but there are some more things that you can add to
a function, so that's what you're going to learn in this lecture and I'll make
this simple I'll delete this and here we are. So here we have only one
parameter, so this is called a function parameter, however you can have more than
one parameters for a function. Let's say seconds, so in this case I allow the
user to enter both minutes and seconds and the program will calculate the hours
based on that, so basically we want to add seconds here, seconds divided by 3600,
So I hope I am fine with the math here. So minutes divided by 60 give you hours.
And then seconds divided by the number of seconds in one hour gives you
the hours and yeah we add them up and we return hours, therefore let me delete
this 10 here. In this case when you call that kind of function with two
parameters, you'd want to pass two values. 60 let's say and 300 for seconds, save.
Execute and you get 1.25 and that's how you can add multiple parameters to your
function and multiple values. Now if you don't pass the value there, one of the,
for one for one of the parameters and you execute, you get a type error. This is
saying type error minutes to hours it's missing one required positional argument
which is seconds, so you are not allowed to miss a value for a positional
argument, so seconds is a positional argument
which you need to pass in the function code and so these are referred to as
arguments when you use them here, when you're talking about function code and
they are referred to as parameters when you pass them in function definition,
so parameters and we're talking about function call you refer to them as
arguments and this is the value of the argument and so positional arguments
need to have a value passed here, but default arguments don't need a value and
a default argument is when you use something like that 70 and let's pass
300 in here, execute. So syntax error. Non default argument follows
default argument. The non default argument here is this on. So positional arguments
such as seconds are also referred to as non default arguments, so the non default argument
second follows the default argument and that gives you syntax error in Python
because Python will get confused when you pass this 300 here so it doesn't
know whether you pass it for this one or for this on here and therefore you need
to pass the default argument after the non default argument, so seconds and
minutes. Now if you save the script and go here, this time you get a correct
output so 1.25. So let me summarize again what's happening. We have a non default
argument and a default argument which has a default value therefore when you
call the function and you pass only one value Python knows that you are you're
passing that value for the non default argument and for the default argument
Python will use the value of 70 however if you pass another value there
they say 200 minutes, so the script executes. You get another output
because python this time used the value of 204 minutes instead of its default
value, so when you don't pass a value Python uses a default value, when you
pass it I can use this what you pass in the function code. So this is useful
when you create functions where some of the arguments will have a value that is
not very likely to change very often. Something else about functions before I
close this lecture. You don't always need a return keyword in here. You can
also do let's say print hours and then you don't need the print statement there.
You just do that execute, and you get the same output, however note that you know if you
do plus 10 now and you execute you get an error because it says NoneType and int,
unsupported operand type for NoneType and integer which means the NoneType is
this one here, so this is not a number and you can see that by doing print,
so print the type of that function, of that output, you'll see that this is an
NoneType so the function doesn't produce a number when you use print, so bottom line
is when it comes to what the function does you have two types of functions you
have a function that generates an output and you have functions that perform some
procedure, so this was an example of a function that performs some procedures
in this case what this function did was it calculated hours and it printed
hours, it didn't return an output and other cases might be like you know when
you create a file so you process some files, you create a text file, you write
some output in that text file and you don't need a return keyword in that case.
But, we will see that later when we cover file
handling in Python. Most of the time though you will have to return a value
here, so that's the idea, this is about this lecture and I'll talk you later.