0

The following code give error:TypeError: test_args_2() takes 1 positional argument but 2 were given

def test_args_2(x, **z):
    print(x, z)
d={'a':4,
   'b':5}
test_args_2(4, d)

Can we use positional and keyword same line?

Tom Karzes
  • 22,815
  • 2
  • 22
  • 41
  • 3
    Use this: `test_args_2(4, **d)` – qrsngky Jun 21 '22 at 03:12
  • 1
    Because `test_args_2(4, d)` means that both `4` and `d` should be positional arguments. `test_args_2(4, **d)` means that `4` should be a positional argument, and the keys of `d` should be the names of keyword arguments, and the corresponding values of `d` should be the values of those keyword arguments. – Karl Knechtel Jun 21 '22 at 03:28
  • 1
    Check out https://docs.python.org/3/glossary.html#term-argument and https://docs.python.org/3/tutorial/controlflow.html#unpacking-argument-lists – HALF9000 Jun 21 '22 at 03:29

0 Answers0