[Tutor] Defining variable arguments in a function in python

Karthik Bhat bhatkarthik1996 at gmail.com
Sat Dec 29 01:12:16 EST 2018


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?


-- 
Regards,
Karthik A Bhat


More information about the Tutor mailing list