0

I have code like this

def my_pow(x=3, *, y=2):
    return x**y
my_pow(4,4)

I know what *args and **kwargs mean, but have no idea what * means between positional arguments.

Why my_pow(4,4) doesn't work? Whereas all variants below do.

my_pow(4,y = 4)
my_pow(x = 4)
my_pow(y = 4)
my_pow(4)
martineau
  • 119,623
  • 25
  • 170
  • 301
Timur
  • 77
  • 6

1 Answers1

1

* marks that arguments after it in the function's definition are keyword-only. It was introduced in Python 3.0.

The reason pow(4, 4) does not work is because of that symbol. Only pow(x=4, y=4) or pow(4, y=4) will work.

Alex Waygood
  • 6,304
  • 3
  • 24
  • 46
BoobyTrap
  • 967
  • 7
  • 18