20. Function Argument Unpacking in Python || * and ** Statements Python Programming Tutorial

Published: 27 June 2022
on channel: Bhavatavi
3
0

Function call with the *operator to unpack the arguments out a list or tuple. When the arguments are in the form of a dictionary, we can unpack them during the function call using the ** operator. A double asterisk ** is used for unpacking a dictionary and passing it as keyword arguments during the function call.

Code:
def _test_a(*args,**kvargs):
if args:
_test_function(*args)
elif kvargs:
_test_function(**kvargs)

def _test_function(stringValue,intValue,floatValue):
print('value1:%s, value2:%d, value3:%f' % (stringValue,intValue,floatValue))

_test_a('Mike',7,5.2)

list_params=['Harry',6,9.2]
_test_a(*list_params)

dict_params={'stringValue':'Tom','intValue':9, 'floatValue':7.2}
_test_a(**dict_params)


On this page of the site you can watch the video online 20. Function Argument Unpacking in Python || * and ** Statements Python Programming Tutorial with a duration of hours minute second in good quality, which was uploaded by the user Bhavatavi 27 June 2022, share the link with friends and acquaintances, this video has already been watched 3 times on youtube and it was liked by 0 viewers. Enjoy your viewing!