Karthik Bhat wrote: > Hello, > > I have the following piece of code. In this, I wanted to make use > of the optional parameter given to 'a', i.e- '5', and not '1' > > def fun_varargs(a=5, *numbers, **dict): > print("Value of a is",a) > > for i in numbers: > print("Value of i is",i) > > for i, j in dict.items(): > print("The value of i and j are:",i,j) > > fun_varargs(1,2,3,4,5,6,7,8,9,10,Jack=111,John=222,Jimmy=333) > > How do I make the tuple 'number' contain the first element to be 1 and > not 2?
One option is to change the function signature to def fun_varargs(*numbers, a=5, **dict): ... which turns `a` into a keyword-only argument. >>> fun_varargs(1, 2, 3, foo="bar"): Value of a is 5 Value of i is 1 Value of i is 2 Value of i is 3 The value of i and j are: foo bar To override the default you have to specify a value like this: >>> fun_varargs(1, 2, 3, foo="bar", a=42) Value of a is 42 Value of i is 1 Value of i is 2 Value of i is 3 The value of i and j are: foo bar _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor