-4

I have a code in python3 and I don't know why the first call doesn't have an error but the second one has?

def one_star_type(a, b, *more):
    print(a + b + sum(more))
    print(type(more))  # <class 'tuple'>

one_star_type(1, 2, 3, 4, 5)

def one_star_type(a, b, **c):
    print(a, b, c)
    print(type(c))

def should_set_value(a, *, b=2, c=5):
    print(a, b, c)

one_star_type(1, 2, 3, 4, 5)

//one_star_type(1, 2, 3, 4, 5)
//TypeError: one_star_type() takes 2 positional arguments but 5 were given
//15
//<class 'tuple'>
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • 5
    `**c` means that the remaining arguments have to be keyword arguments, because `c` will be a dictionary, not a tuple. – Barmar Aug 12 '21 at 23:46

1 Answers1

1

The **c requires keyword arguments, and returns a dictionary. Use *c instead.

Dukk
  • 106
  • 7