2 Comments

Just double checking my understanding here, but does using / to force positional parameters only apply to before the slash? As in it's the opposite of * in every way (positional vs keyword, before vs after)? You don't say explicitly one way or the other, but the TypeError mentions a but not n. So I'm not sure if it was a case of throwing its hands up after one error, or that's just all / was directing it to look for.

At first glance, I would have expected/ to apply to arguments after it, but I supposed that doesn't actually make sense, because my understanding is that you can't put positional arguments after keyword rguments.

And if my understanding of all this is correct, can you stack the slash and splat? Something like def do_math(num1, num2 /* operator): to force passing 2 numbers positionally and then the operator as a keyword argument?

I suppose you could get really fancy and use *args to perform the mathematical operation on any number of numbers like def do_math(*num) /* operator): But I suppose that makes the slash redundant, doesn't it?

Expand full comment

Yes, you got it right

Expand full comment