[no audio]
Friends here we are discussing
about functions with variable length arguments.
So what is meant by variable-length arguments? See,
we know that whenever we define a function, right,
so it may take either one argument, or two arguments, or three,
and based on that we are passing.
Let me open a simple script for that.
Suppose if I define a function 'display', so I want to define
a function just to find out the type of your passed variable.
[no audio]
That's it. Right. Now,
I am calling, suppose.
It's working.
So how many arguments your function is taking? Only one argument,
right. In case if I pass
[no audio]
two arguments, it won't accept because it is taking only one
argument, but we are passing two. Right.
So even though if you pass two arguments suppose if your
function is ready to accept then that is called a variable
length argument function, means number of arguments, whatever
the arguments you are passing, right, the number of arguments
if they vary then that is called variable length arguments
for your functions.
Generally, it won't accept, right. See if I pass 4,
5, now two variables
we are passing. Now
your function is not ready to accept that.
Right. But we have a small syntax for your function to define
such that it is ready to take any number of arguments,
right? Let me define it now. Suppose 'display(*data)'.
Generally, if you Google it, you can see the syntax as 'arg',
argument, '*arg'.
So that is not a standard variable.
You can take any variable because they are arguments
whatever the value we are writing here
they are generally arguments, right,
that's why they are taking 'arg'. Not only that you can take
simply 'data' also.
Right. Then first
let me print what you are getting if we take variable length arguments,
what is the, what type of data you are getting whenever if you
pass your data to your 'display' function. So to know that
I am printing simply your 'data'.
Now, let me call your function.
I am calling without any 'data', without passing any arguments,
zero arguments I am passing.
Now, your function is ready to accept. And observe
the 'data' what you are passing.
Tuple, empty tuple. Now, let me call it with one argument.
Yes, again it is ready to accept one argument as a tuple.
Now, let me call it with some number of values.
Yes, again it is ready to accept. That means see, number of
arguments are varied, right.
This is nothing but variable length arguments. Even though
if you change number of arguments, even though if you pass
number of arguments, each time different number of arguments,
your function is ready to accept that, right. Now to accept that,
nothing is there. Simply write '*', generally '*' means zero or more.
You can pass zero arguments or more number of arguments - 0,
1, or 2, or 3, or 4, any number of arguments you can pass to
your function whenever if you define your parameters as '*',
some variable. Not only 'data' guys, generally 'arg'.
[no audio]
That's it. Now let me comment. Let me comment these two functions,
I mean fourth line and fifth Line.
[no audio]
See, we know if it is a tuple, right,
we can take one by one argument from that, one by one value
from that using loop, for loop, 'for each in your arg'. Guys be
clear, 'arg' is not a fixed variable,
you can take anything. The only thing, whatever the data you
are passing, whatever the arguments you are passing, all arguments
stored into this variable as a tuple. If it is a tuple
I can take one by one value from that, right?
That's what I am doing here.
Now, let me run it and see the result.
[no audio]
Right. Now just for your understanding, just I am calling once again
with different values.
'display()' function,
let me take simply "Hi", and then suppose some 4.6, whatever
it may be data. See that. It's working.
So whether you are passing three arguments or two arguments,
now your function is ready to accept, right?
So this is nothing but simply variable length arguments in
your functions, okay.
Okay guys, thank you for watching this video.
[no audio]