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

Publicado em: 27 Junho 2022
no canal de: 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)


Nesta página do site você pode assistir ao vídeo on-line 20. Function Argument Unpacking in Python || * and ** Statements Python Programming Tutorial duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Bhavatavi 27 Junho 2022, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 3 vezes e gostou 0 espectadores. Boa visualização!