Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Writing a Combined Function

00:00 The combined() function is where we’re basically putting everything together.

00:09 Take away those syntax things. So for people watching, what do you think here? Error, no error? You’ve got three seconds until I run this. And then you’ll see. Three, two, one … Error, because the x needs to be a positional one.

00:29 It’s a positional-only argument. So this will work, and also you can do that with the y,

00:39 but not with the z.

00:43 And why’s that? That’s because we have the * here that says this needs to be a keyword argument. It’s a keyword-only argument. Just walk us over the whole, because it’s a little, there’s a lot of stuff in this function signature, maybe you can just walk us over it. Right, yeah, in the combined() function definition, there’s what appears to be a load of parameters here, but they’re really only three. There’s x, y, and z.

01:10 The special syntax you’ve been exploring is the forward slash (/) and the asterisk (*), which will say everything before the / is a positional-only parameter, and everything after the * is a keyword-only parameter, which means that x can never be called with x= something. It has to be just the value of x.

01:35 y can be either, and z can only be called with z= something. It can’t be shown with just the value. And the error you get here isn’t talking about the keyword-only argument, because it’s looking at the number of positional arguments, and it’s saying that it can take zero to two, but it already knows that you’re passing it three. So it says, “Okay, something’s gone wrong. I haven’t even checked the keyword arguments, but something’s already gone wrong.” So it just gives you the first one. Cool.

Become a Member to join the conversation.