Writing a Keyword-Only Function
And this has been around for longer as well, like Ian already mentioned. Yeah, so it won’t let you just do the positional ones here. You get the
TypeError. And with pretty nice error messages that just tell you that it takes zero positional arguments, but you gave it three. Exactly.
00:36 You can actually do that. It’s a nice thing about keyword arguments—. Yeah, I was going to to say, just mix them up just because you can. That’s one of the nice things about saying you want all of the following ones to be keyword arguments.
00:52 Say you have loads of arguments, and you want people to use them as that and not try and think about the order. And you might just want to use one or two or not all of them at least, you know, and then you don’t need to remember the exact order of which one followed which one. Right. And I imagine you can also do it with this version as well.
01:16 So you don’t need that syntax to do that. It’s, more of a guard against—. The nice thing about it is that it kind of explains the error that you get if you have a mix of positional-only arguments and keyword arguments. Right.
01:40 Which is just a general thing that also doesn’t have anything to do with the syntax, but it still comes into play, I think, into this, in this combined function example that you have next. Right, yeah.
Become a Member to join the conversation.