WEBVTT

00:00.410 --> 00:06.380
Okay, so next up let's cover the optional arguments that have a default value.

00:06.380 --> 00:12.410
And I think we can work in the same file so that we can also take a look at different examples at the

00:12.410 --> 00:13.490
same time.

00:13.490 --> 00:19.640
So for this example let's add another function.

00:19.640 --> 00:23.360
And also let's call it greet with time.

00:23.360 --> 00:27.350
So we're also going to greet a specific person by name.

00:27.350 --> 00:35.690
But also we're going to have an optional time argument that will have a default value of day.

00:37.040 --> 00:42.110
So we're going to be returning a string and saying good time.

00:43.220 --> 00:44.810
So that can be a good day.

00:44.840 --> 00:46.880
Good morning good evening.

00:46.880 --> 00:47.750
Whatever.

00:49.430 --> 00:54.140
So now let's um, call it without this optional argument.

00:54.170 --> 00:56.690
So let's welcome Bob.

00:56.690 --> 01:04.010
And in another call, let's maybe welcome Charlie, but this time saying good evening.

01:06.320 --> 01:09.080
Let's also add a new line here everywhere.

01:09.080 --> 01:12.020
So we have a clear output.

01:12.890 --> 01:13.190
Okay.

01:13.190 --> 01:15.290
Now let's run this function.

01:15.290 --> 01:20.280
So we've got good day, Bob, as time has the default value of day.

01:20.280 --> 01:22.950
And when we provide the argument, there it is.

01:22.950 --> 01:24.210
Good evening.

01:24.210 --> 01:32.040
Now also, the order of the arguments here is pretty important because you can't really have an optional

01:32.040 --> 01:35.010
argument before a required one.

01:35.070 --> 01:43.110
This wouldn't even make any sense, because if I would move the time as the first one, which would

01:43.110 --> 01:50.760
be optional, then what's the point of having an optional argument before our required one?

01:50.760 --> 01:59.370
This would produce really weird syntax, and if I try to call it right now, I've got a different error

01:59.400 --> 02:06.540
saying that too few arguments were passed to greet with time, so one was passed in this example.

02:06.540 --> 02:10.620
Yet we actually have to pass two arguments.

02:10.620 --> 02:16.740
I might try with a comma here, but this is a syntax error.

02:17.880 --> 02:26.910
So as you see, you can't really realistically have the argument that's optional before a required one.

02:26.910 --> 02:30.840
And also it doesn't make any sense at all.

02:31.830 --> 02:31.980
Right.
