1 00:00:00,000 --> 00:00:01,600 [no audio] 2 00:00:01,600 --> 00:00:02,800 Friends, here we are discussing 3 00:00:02,800 --> 00:00:06,800 about functions with variable length keyword- 4 00:00:06,800 --> 00:00:08,900 based arguments. See, already 5 00:00:08,900 --> 00:00:13,000 we know what is a keyword-based argument, right? 6 00:00:13,100 --> 00:00:16,200 See, let me start with that. Already 7 00:00:16,200 --> 00:00:17,200 we know that, right? 8 00:00:17,200 --> 00:00:18,700 Let me define a new script, 9 00:00:18,700 --> 00:00:20,900 [no audio] 10 00:00:20,900 --> 00:00:27,400 'variable_length', keyword based arguments, 'variable_leng_keyword.py'. 11 00:00:27,400 --> 00:00:29,800 [no audio] 12 00:00:29,800 --> 00:00:35,300 Right. See I am displaying a function, I mean I am writing a 'display()', 13 00:00:35,800 --> 00:00:40,300 let's say '(a,b)'. Then just simply I am writing 'print(a)' 14 00:00:40,500 --> 00:00:42,200 and then 'print(b)' value. 15 00:00:42,200 --> 00:00:44,300 [no audio] 16 00:00:44,300 --> 00:00:45,600 Right. Now 17 00:00:47,200 --> 00:00:48,500 let me write 'return None'. 18 00:00:49,600 --> 00:00:52,600 Now while calling your function you can pass in this way. 19 00:00:52,800 --> 00:00:55,600 Right. It will work. At the same time, 20 00:00:55,600 --> 00:00:58,500 if you remember already we discussed keyword-based arguments. 21 00:00:58,900 --> 00:01:04,800 I can write '(b=5,a=4)'. Now see the result. 22 00:01:05,000 --> 00:01:07,400 or I can also start with the 'a'. 23 00:01:09,000 --> 00:01:12,000 Based on key I am passing my value, right? 24 00:01:12,900 --> 00:01:16,900 So, this is called keyword-based arguments in your functions. 25 00:01:17,700 --> 00:01:25,400 It's working, right. But our concept is variable-length keyword- 26 00:01:25,400 --> 00:01:29,700 based arguments. Variable-length keyword-based arguments means 27 00:01:30,000 --> 00:01:34,600 next time whenever if I am calling I'm also passing one extra 28 00:01:34,600 --> 00:01:37,400 value. Let's say in this way. 29 00:01:37,900 --> 00:01:41,600 Now, we know that our function is ready to accept only (a,b), 30 00:01:41,600 --> 00:01:44,200 two arguments, but we are passing three arguments based 31 00:01:44,200 --> 00:01:47,300 on keys, now it's not ready to accept. 32 00:01:48,600 --> 00:01:52,900 Right. Now again, nothing is there. It's again like a variable 33 00:01:52,900 --> 00:01:54,900 length arguments only but based on keys. 34 00:01:54,900 --> 00:01:56,900 [no audio] 35 00:01:56,900 --> 00:02:01,100 Whenever if we have a variable length of arguments, so this 36 00:02:01,100 --> 00:02:03,000 time I'm passing two arguments, here 37 00:02:03,000 --> 00:02:05,400 I am passing three arguments but based on keys. 38 00:02:06,100 --> 00:02:08,100 So, based on keys 39 00:02:08,100 --> 00:02:12,100 if you are passing variable length arguments, to handle them 40 00:02:12,100 --> 00:02:13,199 in your function 41 00:02:13,500 --> 00:02:17,000 we have a syntax like this '(**)', 42 00:02:18,300 --> 00:02:20,100 keyword-based arguments, 'karg', 43 00:02:21,000 --> 00:02:22,400 keyword-based arguments. 44 00:02:22,400 --> 00:02:25,600 That's why I'm taking simply 'k-a-r-g', but you can take anything. 45 00:02:26,300 --> 00:02:28,500 Simply this is a variable, variable name. 46 00:02:28,500 --> 00:02:32,400 I'm taking 'karg', keyword-based arguments. Right. 47 00:02:32,400 --> 00:02:37,400 Now, let me print what you are getting because of this '**'. 48 00:02:38,100 --> 00:02:42,300 So, what is the 'karg' now. Right. See the result. 49 00:02:43,600 --> 00:02:45,800 You know, we are not passing based on keys, this function, 50 00:02:45,800 --> 00:02:48,100 right. Now see the result. 51 00:02:49,300 --> 00:02:53,100 Here we are passing based on keys, whenever if you pass based 52 00:02:53,100 --> 00:02:55,800 on keys and whenever if you have a syntax in your function 53 00:02:55,800 --> 00:02:59,100 with '**' in a variable, then that variable is nothing 54 00:02:59,100 --> 00:03:02,400 but a dictionary which consists of key and value pair representation. 55 00:03:02,800 --> 00:03:05,500 Already we know what is the key and value pair representation. 56 00:03:05,600 --> 00:03:06,400 That's what it is. 57 00:03:06,800 --> 00:03:11,700 See that. You're writing based on key and value only, right. Now, next 58 00:03:11,700 --> 00:03:12,900 time I can pass 59 00:03:12,900 --> 00:03:14,900 [no audio] 60 00:03:14,900 --> 00:03:16,800 not only 'a', you can take anything. 61 00:03:17,100 --> 00:03:30,000 Let's say I am taking '(x=5,y="Hi"',z=6.7, path=root)', 62 00:03:30,000 --> 00:03:32,600 something like that, or 'user=root', 63 00:03:32,600 --> 00:03:33,600 instead of 'path'. 64 00:03:33,600 --> 00:03:35,200 [no audio] 65 00:03:35,200 --> 00:03:36,200 Now see the result. 66 00:03:37,500 --> 00:03:41,200 So inside of your function you are getting the passed, 67 00:03:41,400 --> 00:03:43,900 whatever the arguments you are passing based on keys 68 00:03:44,200 --> 00:03:48,300 they all are forming a dictionary with this variable. 69 00:03:48,400 --> 00:03:50,700 That's what we are printing here. That's it. 70 00:03:50,100 --> 00:03:50,700 That's it. 71 00:03:51,900 --> 00:03:56,800 Right. So, guys, you can also combine your keyword-based arguments 72 00:03:56,900 --> 00:03:58,000 with some variable as well. 73 00:03:58,000 --> 00:04:01,000 Let's say I am taking here some letter 'p', 74 00:04:01,100 --> 00:04:04,500 I mean variable 'p'. Now very first I need to pass some value. 75 00:04:04,500 --> 00:04:05,600 Let's say 56. 76 00:04:07,600 --> 00:04:09,100 You can 'print(p)' also here. 77 00:04:10,000 --> 00:04:13,500 So just combination of normal argument and then keyword-based 78 00:04:13,500 --> 00:04:14,800 arguments, combination. 79 00:04:15,900 --> 00:04:16,810 Something wrong. 80 00:04:16,800 --> 00:04:20,399 [no audio] 81 00:04:23,200 --> 00:04:26,399 Yeah, in this function, seventh, eighth. Sixth and seventh, 82 00:04:26,399 --> 00:04:30,200 we are not passing there, right. Don't worry. See that. 83 00:04:30,200 --> 00:04:32,400 [no audio] 84 00:04:32,400 --> 00:04:36,200 So, we are passing for 'p' first value, remaining all are key-based 85 00:04:36,200 --> 00:04:39,300 arguments. The same way you have to pass in the seventh line 86 00:04:39,300 --> 00:04:42,100 and sixth line so that the value of 'p' will be assigned to 87 00:04:42,100 --> 00:04:45,000 'p', I mean first value, remaining all are like you know 88 00:04:45,000 --> 00:04:49,300 key-based arguments. So they will form a dictionary. That's it. 89 00:04:50,100 --> 00:04:55,100 So, this is a simple way to create variable length key-based 90 00:04:55,100 --> 00:04:56,800 arguments for your functions. 91 00:04:57,500 --> 00:05:02,200 Okay. So guys by this we completed all the possible syntaxes, 92 00:05:02,200 --> 00:05:06,300 all the possible ways to define your functions, right? 93 00:05:06,300 --> 00:05:10,700 Next, we'll try to write a script by using all these concepts one by one, 94 00:05:11,400 --> 00:05:16,100 okay. Be ready with all these concepts so that we can easily 95 00:05:16,300 --> 00:05:19,700 understand while writing your code using different syntaxes 96 00:05:19,700 --> 00:05:22,200 of different types of your functions. 97 00:05:23,300 --> 00:05:25,900 Okay. Okay guys, thank you for watching this video. 98 00:05:25,900 --> 00:05:32,500 [no audio]