Hola Everyone. Today we will be reading about functions and functional arguments.
So, let me first tell you why functions are used. So basically, functions are used to make a code reusable. For e.g.

Here we can check whether a given number is prime or not, but it can be used only once. So, make this code reusable we will keep this suite of code inside a function.

Here, I wrote a function isprime and I am using it again and again as I am iterating over x. Here, i is an argument which I passed it along the function call.
Now, let us read about some types of arguments that can be passed with the function. In the previous example, we saw a formal argument which has a reference in the function definition.
What if we want to send a list of arguments and we are not sure about the no of arguments to be passd.Python allows us to handle this kind of situation through function calls with arbitrary number of arguments. It can be done as shown below.

Here, the arguments which do not have direct reference are taken as a tuple and stored in args.
Similarly, sometimes we need to pass keyword arguments. A keyword argument is where you provide a name to the variable as you pass it into the function.

The functional arguments are passed as a key-value pair and are stored in a dictionary (here kwargs).
These arguments can be combined very easily but we must follow a convention in passing these arguments. First, formal arguments should be passed, then the list of arguments, then keyword arguments.

Here, you can see we passed all the three types of arguments, first we passed formal arguments (here 1,2,3) then the list of arguments (here 4,5,6) then keyword arguments (here one=1, two=2, three=3). This is the only thing you should care while using functional arguments.
Now, let us talk about a special function called generator function
These functions return an iterator object. Instead of return they use yield.


So, yield is used to provide a result to its caller without destroying local variables. Unlike a function, where on each call it starts with new set of variables, a generator will resume the execution where it was left off