1 00:00:02,170 --> 00:00:13,020 In this session we will talk about the arguments Asterix and double asterisks keywords. 2 00:00:13,420 --> 00:00:17,280 So what is Asterix eggs. 3 00:00:17,470 --> 00:00:26,380 This is a non key word argument that is used to parse multiple argument values to a function. 4 00:00:26,380 --> 00:00:37,330 So let's understand this using examples so here to help define the function at which takes two parameters 5 00:00:37,570 --> 00:00:48,430 A and B and within the function body B are printing the sum of the these two parameters and b here is 6 00:00:48,430 --> 00:00:57,280 the function call we have parsed to argument and coming to the function at which I have defined here. 7 00:00:57,420 --> 00:01:08,560 This function takes in three parameters A B and C and the function body here also does the same. 8 00:01:08,580 --> 00:01:15,610 That means it adds all the three arguments A B and C and displays the output. 9 00:01:15,690 --> 00:01:20,750 And here is a function called so in the first function call to see. 10 00:01:20,750 --> 00:01:26,520 Here we have parsed two arguments in the second function call. 11 00:01:26,970 --> 00:01:35,180 We have parsed three arguments but these functions are doing pretty much the same. 12 00:01:35,210 --> 00:01:42,070 They're displaying the sum of the argument that are received through the function called 13 00:01:45,180 --> 00:01:46,300 now. 14 00:01:46,410 --> 00:01:57,060 How would you define a function that takes in variable number of arguments and execute these same set 15 00:01:57,150 --> 00:02:05,000 of steps irrespective of the number of argument it a C say for example. 16 00:02:05,050 --> 00:02:13,780 In this particular function call we are passing in two arguments in this we are passing five and here 17 00:02:14,170 --> 00:02:17,710 we are passing seven arguments. 18 00:02:17,830 --> 00:02:30,840 So how do you define your function such that it takes an variable number of arguments C in Python allows 19 00:02:30,840 --> 00:02:44,310 us to parse variable number of arguments to a function using Asterix X so when we are not sure about 20 00:02:44,310 --> 00:02:53,130 the number of arguments you pass to a function we can use this as tricks args 21 00:02:55,900 --> 00:03:08,940 remember does not necessary to write start args as the parameter only the Asterix is mandatory. 22 00:03:08,940 --> 00:03:23,250 You could also write Asterix that are Asterix X as your parameter writings Asterix ARGs and double asterisks 23 00:03:23,890 --> 00:03:26,340 keywords is just a convention 24 00:03:29,330 --> 00:03:29,880 D. 25 00:03:29,910 --> 00:03:38,820 Asterix ARGs that we have defined here is also known as non keyword argument. 26 00:03:39,000 --> 00:03:50,730 So when we make a function call to such function the arguments that we pass in this example one comma 27 00:03:50,780 --> 00:04:02,310 to add parsed as a tuple to the function and these parsed argument make tuple inside the function with 28 00:04:02,310 --> 00:04:05,310 the same name as the parameter 29 00:04:07,520 --> 00:04:20,720 excluding the Asterix the variable that we associate with the Asterix becomes an item about so you can 30 00:04:20,780 --> 00:04:24,280 either it or the elements in your tuple 31 00:04:27,770 --> 00:04:37,600 so I have defined of function addition which has a non keyword arguments so here I have defined the 32 00:04:37,600 --> 00:04:43,110 function addition which has the non keyword argument. 33 00:04:43,150 --> 00:04:51,640 That means we can pass variable number of argument to this function addition and in the function body 34 00:04:51,640 --> 00:04:55,890 we're returning the sum of the arguments pass to this function. 35 00:04:56,020 --> 00:05:03,790 So we have a function call here through which we are passing five arguments so let's execute this piece 36 00:05:03,880 --> 00:05:08,930 of code so here we have these some of these arguments. 37 00:05:09,000 --> 00:05:20,480 Now let us pass a different set of arguments say one comma for comma 5 and then execute. 38 00:05:20,480 --> 00:05:27,470 Here we have these sum so as you can see the same function can be used irrespective of the number of 39 00:05:27,470 --> 00:05:38,150 arguments pass to the function the the arguments are parsed as a tuple and these parsed arguments make 40 00:05:38,150 --> 00:05:44,600 a tuple inside the function with the same name as the parameter excluding the asterisks. 41 00:05:45,110 --> 00:05:50,410 So let's see what is being assigned to this variable args. 42 00:05:50,570 --> 00:05:59,900 After we make a function call and also let us see what is the type. 43 00:06:00,230 --> 00:06:10,370 The data type of this non keyword ID argument and then execute this function line of code as you can 44 00:06:10,370 --> 00:06:20,450 see a tuple has been assigned to this non keyword ID argument ARGs and then this is the data type of 45 00:06:20,540 --> 00:06:27,940 the variable args it is a tuple and then we are returning the some of the arguments 46 00:06:30,940 --> 00:06:37,150 so when we execute this line of code with these three set of arguments. 47 00:06:37,150 --> 00:06:44,100 So here the tuple containing these three elements has been assigned to the non keyword argument dogs. 48 00:06:44,320 --> 00:06:51,790 It is of the type tuple and then we have these some of the arguments in the output 49 00:06:54,880 --> 00:07:03,800 byte and passes variable and non keyword arguments to a function using Asterix ARGs that we have just 50 00:07:03,800 --> 00:07:05,150 talked about. 51 00:07:05,510 --> 00:07:14,840 If we want to parse keyword arguments to a function such as like this here we have a bit of key and 52 00:07:14,960 --> 00:07:25,420 value key and value if you want to pass an argument in this form in the form of a key and a value you 53 00:07:25,420 --> 00:07:30,020 can use the non key worded argument. 54 00:07:30,250 --> 00:07:39,090 Double asterisk K works and this allows us to pass where you blend of keyword arguments to a function 55 00:07:40,570 --> 00:07:50,950 and B use a double asterisks before the parameter name to denote this type of argument and the arguments 56 00:07:51,000 --> 00:08:00,640 are parsed as a dictionary and these arguments make a dictionary inside the function with the same name 57 00:08:00,700 --> 00:08:04,390 as the parameter excluding the double Asterix. 58 00:08:04,570 --> 00:08:15,340 So in case of the non keyword ID argument the arguments are parsed as a tuple a comma B comma C and 59 00:08:15,910 --> 00:08:23,150 then within the function that assigned to the non keyword ID argument. 60 00:08:23,670 --> 00:08:33,310 But coming to K walks the key value pairs are a sign in the form of a dictionary. 61 00:08:33,380 --> 00:08:36,040 This is how they are to present to 62 00:08:38,840 --> 00:08:47,660 and then we remove the double asterisks assigned to the keyword argument. 63 00:08:47,670 --> 00:08:54,070 K Boggs again the double asterisks K Boggs is not necessity. 64 00:08:54,090 --> 00:08:58,680 Only the double Asterix is necessary. 65 00:08:58,740 --> 00:09:07,210 We can also write this as double Asterix word or double asterisks X.. 66 00:09:07,770 --> 00:09:17,020 Writing a single Asterix out and double asterisk K was is just a convention. 67 00:09:17,040 --> 00:09:20,410 Here is an example for the keyword arguments. 68 00:09:20,770 --> 00:09:28,390 So the function sample one printout the key word id argument. 69 00:09:28,780 --> 00:09:36,250 So in the function call we have passed a pair of key while you pairs and d argument. 70 00:09:36,400 --> 00:09:45,970 The key value arguments are parsed as a dictionary to the function and the arguments make a dictionary 71 00:09:45,970 --> 00:09:50,890 inside the function with the same name as the parameter name. 72 00:09:50,890 --> 00:10:00,560 Excluding the double asterisks so after calling the function within the function body we have displayed 73 00:10:00,950 --> 00:10:02,850 debatable K bugs. 74 00:10:02,960 --> 00:10:12,760 Let us check the data type of the variable K args so it is of the type. 75 00:10:12,820 --> 00:10:22,960 Dictionary keyword argument is a dictionary so we can perform the various operations that can be performed 76 00:10:23,020 --> 00:10:24,340 on a dictionary. 77 00:10:24,640 --> 00:10:31,290 So letters display the items in this dictionary. 78 00:10:31,400 --> 00:10:41,460 So for that K logs dart items so here we have a list of key value pairs. 79 00:10:43,650 --> 00:10:53,640 In the output as you can see up until now we have used the asterisks args or the double asterisks K 80 00:10:53,640 --> 00:11:07,420 bugs in the parameter of a function but we can also pass the Asterix args as an argument in the function 81 00:11:07,420 --> 00:11:10,320 call. 82 00:11:10,380 --> 00:11:22,920 So in this example I have assigned a tuple to this variable variable 1 and parse this variable at as 83 00:11:22,980 --> 00:11:34,100 an argument to the function called so when we do this the Asterix here unbanked the items in the Japan 84 00:11:34,860 --> 00:11:38,280 and then passes it to the function sample. 85 00:11:41,060 --> 00:11:51,590 The Asterix unpacks these elements in the eye trouble such as a tuple or or list and then these values 86 00:11:52,070 --> 00:12:04,970 sent as positional arguments to the function being called so the elements in the tuples unpacked and 87 00:12:05,390 --> 00:12:08,010 sent to this function. 88 00:12:08,150 --> 00:12:16,640 The value 1 is assigned to the parameter e in the function definition while you do is assigned to B 89 00:12:17,240 --> 00:12:27,470 then value 3 is assigned to see or hear to have defined a function at and an array double bad which 90 00:12:27,620 --> 00:12:35,900 is a tuple containing these elements and to the function call we have passed a non keyword argument 91 00:12:36,680 --> 00:12:47,120 Asterix Ward and this Asterix unbanked D element in the tuple into positional arguments and these positional 92 00:12:47,120 --> 00:12:50,420 arguments are parsed to this. 93 00:12:50,480 --> 00:13:02,260 Function and each of these elements D positional arguments are assigned to the parameters here A B and 94 00:13:02,260 --> 00:13:10,720 C so we have displayed these the values of each of these elements in the tuple as you can see 95 00:13:14,170 --> 00:13:21,400 the parameters have been mapped to the positional arguments and then finally using the return statement 96 00:13:21,640 --> 00:13:30,280 we are displaying the sum of the argument passed through the function call similarly we can pass key 97 00:13:30,390 --> 00:13:41,300 word argument in the function call like this using double asterisks sign and the double asterisks unpacks 98 00:13:41,300 --> 00:13:44,860 the elements in the dictionary. 99 00:13:44,930 --> 00:13:55,010 That is the key value pairs in the dictionary as argument and it as keyword argument to the function 100 00:13:55,040 --> 00:13:56,090 that is being called 101 00:13:59,300 --> 00:14:08,260 we can use the key word a non keyword argument in combination with the normal argument. 102 00:14:08,480 --> 00:14:11,950 Also known as formal arguments. 103 00:14:12,020 --> 00:14:22,370 So here as you can see in the function call we have a normal argument as your first argument and then 104 00:14:22,370 --> 00:14:26,290 we have a non key worded argument. 105 00:14:26,390 --> 00:14:36,210 So when we make a function call the Asterix here that you see unpacks the elements in the tuple 106 00:14:39,660 --> 00:14:41,980 in due positional parameters 107 00:14:45,270 --> 00:14:57,950 and then all these arguments are parsed to the function so the argument Apple is assigned to the parameter 108 00:14:58,060 --> 00:15:10,200 a the value 5 is assigned to B and so on so in this example here I have parsed a formal argument as 109 00:15:10,200 --> 00:15:18,840 the first positional parameter in the function call and then we have the non keyword argument parse 110 00:15:18,840 --> 00:15:29,680 through the Asterix using the asterisks and then we have two key value pairs as argument. 111 00:15:29,680 --> 00:15:37,750 And finally we have the key word arguments pass through using the double asterisks sign. 112 00:15:37,900 --> 00:15:47,860 So when we make a function call argument one is parsed as the first positional parameter and then we 113 00:15:47,860 --> 00:15:56,290 have the asterisks which which unpacks these elements in the tuple into positional parameters and then 114 00:15:56,290 --> 00:16:04,270 we have two key value bits that are parsed in the function call after the non keyword argument and then 115 00:16:04,270 --> 00:16:12,010 we have the keyword arguments pass using did double asterisks sign and this double asterisks sign unpacks 116 00:16:12,040 --> 00:16:15,760 the items in the dictionary. 117 00:16:15,760 --> 00:16:26,400 Here so when we execute this in the value one has been mapped to this parameter a and then we have the 118 00:16:26,400 --> 00:16:34,400 elements and the trooper it to unpack then map it to the parameters B and C and so on. 119 00:16:35,940 --> 00:16:44,840 And then finally we are printing each of the arguments the first one is d form argument then we have 120 00:16:44,840 --> 00:16:50,500 the non keyword argument and then we have the key value pairs. 121 00:16:51,350 --> 00:17:00,980 And finally we have the keyword arguments displayed in the output men passing arguments to a function 122 00:17:01,040 --> 00:17:06,510 we need to follow this order then passing the arguments. 123 00:17:06,510 --> 00:17:14,190 So first we need to list all the formal arguments of the normal argument and then we have the non key 124 00:17:14,190 --> 00:17:15,890 worded arguments. 125 00:17:15,900 --> 00:17:26,650 And finally D key worded arguments and this brings us to the end of the topic keyword and non keyword 126 00:17:26,770 --> 00:17:27,520 arguments.