*args and **kwargs in Python

Python accepts a list or a dictionary as arguments in function. This is very useful. Look at this code example:

def TestArgs(titleid, typename, *args, **kwargs):
    print titleid,typename
    print "**************"
    for val in args:
         print val

    for k,v in kwargs.iteritems():
        print k,v

if __name__ == '__main__':
    TestArgs(69,"ps4", 1,"2","6")

The output is:
69 ps4
**************
1
2
6

Continue reading *args and **kwargs in Python

Advertisements