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

Publié le: 27 juin 2022
sur la chaîne: 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)


Sur cette page du site, vous pouvez voir la vidéo en ligne 20. Function Argument Unpacking in Python || * and ** Statements Python Programming Tutorial durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Bhavatavi 27 juin 2022, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 3 fois et il a aimé 0 téléspectateurs. Bon visionnage!