[no audio]
Friends, here we are discussing
about functions with variable length keyword-
based arguments. See, already
we know what is a keyword-based argument, right?
See, let me start with that. Already
we know that, right?
Let me define a new script,
[no audio]
'variable_length', keyword based arguments, 'variable_leng_keyword.py'.
[no audio]
Right. See I am displaying a function, I mean I am writing a 'display()',
let's say '(a,b)'. Then just simply I am writing 'print(a)'
and then 'print(b)' value.
[no audio]
Right. Now
let me write 'return None'.
Now while calling your function you can pass in this way.
Right. It will work. At the same time,
if you remember already we discussed keyword-based arguments.
I can write '(b=5,a=4)'. Now see the result.
or I can also start with the 'a'.
Based on key I am passing my value, right?
So, this is called keyword-based arguments in your functions.
It's working, right. But our concept is variable-length keyword-
based arguments. Variable-length keyword-based arguments means
next time whenever if I am calling I'm also passing one extra
value. Let's say in this way.
Now, we know that our function is ready to accept only (a,b),
two arguments, but we are passing three arguments based
on keys, now it's not ready to accept.
Right. Now again, nothing is there. It's again like a variable
length arguments only but based on keys.
[no audio]
Whenever if we have a variable length of arguments, so this
time I'm passing two arguments, here
I am passing three arguments but based on keys.
So, based on keys
if you are passing variable length arguments, to handle them
in your function
we have a syntax like this '(**)',
keyword-based arguments, 'karg',
keyword-based arguments.
That's why I'm taking simply 'k-a-r-g', but you can take anything.
Simply this is a variable, variable name.
I'm taking 'karg', keyword-based arguments. Right.
Now, let me print what you are getting because of this '**'.
So, what is the 'karg' now. Right. See the result.
You know, we are not passing based on keys, this function,
right. Now see the result.
Here we are passing based on keys, whenever if you pass based
on keys and whenever if you have a syntax in your function
with '**' in a variable, then that variable is nothing
but a dictionary which consists of key and value pair representation.
Already we know what is the key and value pair representation.
That's what it is.
See that. You're writing based on key and value only, right. Now, next
time I can pass
[no audio]
not only 'a', you can take anything.
Let's say I am taking '(x=5,y="Hi"',z=6.7, path=root)',
something like that, or 'user=root',
instead of 'path'.
[no audio]
Now see the result.
So inside of your function you are getting the passed,
whatever the arguments you are passing based on keys
they all are forming a dictionary with this variable.
That's what we are printing here. That's it.
That's it.
Right. So, guys, you can also combine your keyword-based arguments
with some variable as well.
Let's say I am taking here some letter 'p',
I mean variable 'p'. Now very first I need to pass some value.
Let's say 56.
You can 'print(p)' also here.
So just combination of normal argument and then keyword-based
arguments, combination.
Something wrong.
[no audio]
Yeah, in this function, seventh, eighth. Sixth and seventh,
we are not passing there, right. Don't worry. See that.
[no audio]
So, we are passing for 'p' first value, remaining all are key-based
arguments. The same way you have to pass in the seventh line
and sixth line so that the value of 'p' will be assigned to
'p', I mean first value, remaining all are like you know
key-based arguments. So they will form a dictionary. That's it.
So, this is a simple way to create variable length key-based
arguments for your functions.
Okay. So guys by this we completed all the possible syntaxes,
all the possible ways to define your functions, right?
Next, we'll try to write a script by using all these concepts one by one,
okay. Be ready with all these concepts so that we can easily
understand while writing your code using different syntaxes
of different types of your functions.
Okay. Okay guys, thank you for watching this video.
[no audio]