SNIPPET
1 Upvote

Unpacking Args and Kwargs

Python
General Python

Example of using for loops to unpack and print args and kwargs. The python single asterisk operator is used to pass positional arguments passed while the double asterisk is used for keyword arguments.

def print_args(*args,**kwargs):
    for i in args:
        print(i)
    for j in kwargs:
        print('{0}: {1}'.format(j, kwargs[j]))

print_args(1,2,3,a=10,b=20)

>> 1
>> 2
>> 3
>> a: 10
>> b: 20

By detro - Last Updated Nov. 20, 2021, 4:17 p.m.

COMMENTS
RELATED SNIPPETS
Python For Else Loop
Python
General Python

Loop

2
Search Snippets by Tag: