Python automatycznie rozpakowuje *args
i **kwargs
do odpowiednich pozycji w sygnaturze funkcji. Jeśli po tym rozpakowaniu okaże się, że funkcja nie ma odpowiednich parametrów, wtedy zostanie zgłoszony błąd TypeError
. Przyjrzyjmy się temu bliżej.
-
Rozpakowywanie
*args
*args
pozwala funkcji przyjmować dowolną liczbę argumentów pozycyjnych. Te argumenty są przekazywane jako krotka.def example_func(a, b, *args):