Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language 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.

Introducing Positional and Keyword Arguments

00:00 So I’ve got four functions here, and I’m loaded into an IPython interactive session. I have access to all these functions, and we’re going to just play around with them and call them with positional arguments, with keyword arguments, and see what happens.

00:17 So the first function is standard(), and as you see, we’ve got—in all cases, we’ve got—an x, y, and z parameter that are set with default values to 1.

00:31 So that means we can call standard(), for instance, with nothing, and it will just use the default values. We’re not doing anything with any of these functions. We’re just passing.

00:41 So as long as there are no errors, we’re doing everything okay.

00:46 With the standard way, you can also name them,

00:53 and that works fine as well. You can’t do things like have a positional one after the keyword argument, and that’s nothing to do with this syntax exactly. It’s just, you can’t ever have a positional argument that is something without a keyword or a named argument that comes after. So what you maybe want to show here too, before we go into this, is how you would call the standard() function with actual, just positional arguments because if—. Right.

01:21 I think you only shared it with the keyword arguments now. Right, yeah, I skipped out that part. So you can call it with just your standard positional arguments,

01:32 and yeah, and this last example was just something I wanted to sort of draw attention to: that you can’t have the positional arguments after keyword arguments.

01:40 And do you still call these positional arguments when you give them default values? How do you mean, call the values? Like, if I look at this standard() function and that it is x=1, like when I look at this, like up here—. Yeah.

01:55 The first thing I think about is that these are keyword arguments because they have the equal sign in between. Right. They can be keyword arguments, but they can also be positional arguments.

02:07 So, like, just a pure positional argument, I could also do this. So I would have x as a positional argument—. Right. Without a default value.

02:16 Yes, but then you’d have to provide that with a value when you’re calling it.

02:21 So if you go back up to the top one, if I had this as just x, you could also call that as a keyword argument, as x=1. You could call that as a positional argument, with just 1.

02:34 But you wouldn’t be able to skip it.

02:37 So what really distinguishes, in terms of the function definition, with the parameters in there? What really distinguishes a positional argument from a keyword argument?

02:47 Good question.

Become a Member to join the conversation.