1
00:00:00,210 --> 00:00:05,210
In the last lesson, we saw how different it was when we tried to use the turtle's

2
00:00:05,400 --> 00:00:06,480
write function

3
00:00:06,780 --> 00:00:11,780
and we saw all of the arguments available listed, versus when we tried to use the

4
00:00:12,210 --> 00:00:14,940
Tkinter label's pack method,

5
00:00:15,330 --> 00:00:20,100
and notice how there's actually very few arguments that are listed.

6
00:00:20,520 --> 00:00:24,000
And yet, somehow there's all of these parameters that we can change

7
00:00:24,240 --> 00:00:28,650
when we look at the documentation, like expand or side.

8
00:00:29,010 --> 00:00:32,340
So let's set that side to equal left,

9
00:00:32,700 --> 00:00:35,730
and I'm going to delete the rest of the turtle code.

10
00:00:36,150 --> 00:00:41,150
And now you can see our label is placed on the left side of our screen.

11
00:00:42,900 --> 00:00:45,030
How is it that these parameters,

12
00:00:45,090 --> 00:00:48,090
even though they're not listed in the list of properties,

13
00:00:48,330 --> 00:00:52,770
how is it that we're able to use them just by typing them in? Well,

14
00:00:52,800 --> 00:00:57,510
to understand this, we have to learn a bit more about advanced arguments.

15
00:00:57,900 --> 00:00:59,430
Not how to argue better,

16
00:00:59,520 --> 00:01:04,519
but how to use advanced Python arguments in order to specify a wider

17
00:01:06,330 --> 00:01:07,890
range of inputs.

18
00:01:08,790 --> 00:01:12,870
We've already seen how keyword arguments work. For example,

19
00:01:12,870 --> 00:01:17,430
here I have a function and I have three keyword arguments,

20
00:01:17,490 --> 00:01:20,280
a, b, and c. And when I call the function,

21
00:01:20,610 --> 00:01:25,320
I can provide those inputs, a, b, and c in any order I want

22
00:01:25,650 --> 00:01:27,930
as long as I've got the keyword in front.

23
00:01:27,990 --> 00:01:31,020
So c = 3, a = 1, and b = 2.

24
00:01:31,980 --> 00:01:34,980
Now what if when I use this function,

25
00:01:35,370 --> 00:01:40,370
it's nine out of ten times, a is going to be equal to 1, b is 2 and c as 3.

26
00:01:41,460 --> 00:01:46,110
Why is it that when I call the function, I always have to put in these values?

27
00:01:46,170 --> 00:01:48,510
That seems a bit of a wasted effort, right?

28
00:01:49,020 --> 00:01:53,850
Python has a very neat way of solving this by creating arguments that have

29
00:01:53,940 --> 00:01:55,320
default values.

30
00:01:55,830 --> 00:01:59,160
We can do this by simply changing the function declaration.

31
00:01:59,550 --> 00:02:01,470
So when we create our function,

32
00:02:01,590 --> 00:02:05,970
we can already give it some values to start off with. So we can say that a

33
00:02:05,970 --> 00:02:09,870
should be equal to 1, b = 2 and c = 3, and these

34
00:02:09,940 --> 00:02:11,370
are the default values.

35
00:02:11,790 --> 00:02:15,900
So that means when I call this function and I want to use the default values,

36
00:02:16,290 --> 00:02:20,670
I don't actually have to provide any inputs and it will just go along as it

37
00:02:20,670 --> 00:02:22,740
would before. Now,

38
00:02:22,800 --> 00:02:26,400
if, however, I wanted to modify one of those inputs,

39
00:02:26,430 --> 00:02:29,220
let's say I wanted to give a custom value for b

40
00:02:29,520 --> 00:02:32,880
rather than let it be equal to the default value of 2, well,

41
00:02:32,880 --> 00:02:37,880
then I can just change the value of b, b = 5. And the rest,

42
00:02:38,640 --> 00:02:42,240
so a and c, will still take on their default values.

43
00:02:42,990 --> 00:02:46,140
Notice when I called tim.write,

44
00:02:46,590 --> 00:02:50,730
this write method takes five inputs; self,

45
00:02:50,760 --> 00:02:54,240
because it's a method and associated with the turtle class,

46
00:02:54,690 --> 00:02:57,750
it takes an argument which is what it is going to write,

47
00:02:58,050 --> 00:03:00,910
move, align and font. Now,

48
00:03:01,360 --> 00:03:04,690
if I wanted to use tim.turtle to just write

49
00:03:04,690 --> 00:03:06,370
some sort of text,

50
00:03:08,350 --> 00:03:12,820
I can actually just put in this. And when I run this code,

51
00:03:13,720 --> 00:03:17,320
you'll see that I've got some piece of text being written.

52
00:03:18,280 --> 00:03:22,300
But how is it that I've got all of these other inputs

53
00:03:22,360 --> 00:03:26,620
which I've just basically completely ignored? What about move?

54
00:03:26,650 --> 00:03:31,000
What about align? What about fonts? Well, as you can see,

55
00:03:31,330 --> 00:03:34,330
they have the =...,

56
00:03:34,660 --> 00:03:38,860
which is trying to tell you that they've already got a default value.

57
00:03:39,370 --> 00:03:42,160
And in fact, if I hover over this write function,

58
00:03:42,220 --> 00:03:45,940
you can see that in the quick docs that pops up,

59
00:03:46,150 --> 00:03:47,860
it tells me that the argument,

60
00:03:48,210 --> 00:03:50,100
or the arg,

61
00:03:50,490 --> 00:03:54,450
which is what it is to be written to the screen, move

62
00:03:54,510 --> 00:03:58,380
which is optional which can be set as true or false, align

63
00:03:58,380 --> 00:04:01,140
which is optional, font which is optional.

64
00:04:01,710 --> 00:04:06,420
The reason why they're optional is because all of these actually have a default

65
00:04:06,420 --> 00:04:07,860
value. For example,

66
00:04:07,860 --> 00:04:12,860
move, by default, is false; align by default is centered,

67
00:04:14,070 --> 00:04:15,960
and there's also a default font.

68
00:04:16,920 --> 00:04:21,920
So that means that all we have to do is just to provide the required arguments.

69
00:04:23,340 --> 00:04:27,930
If I don't add anything at all when I call this write method, you can see

70
00:04:27,930 --> 00:04:30,090
I do in fact get an error here.

71
00:04:30,300 --> 00:04:34,650
And it says write is missing one required positional argument,

72
00:04:34,890 --> 00:04:37,260
which is that first arg

73
00:04:37,620 --> 00:04:41,130
which is the thing that it's expecting to write. I mean,

74
00:04:41,130 --> 00:04:44,520
if you're calling turtle to do some writing and you not telling it what to write,

75
00:04:44,790 --> 00:04:45,870
that's a bit of a problem.

76
00:04:46,200 --> 00:04:51,200
So this ARG is a required argument because it doesn't have that =... at

77
00:04:52,590 --> 00:04:56,910
the end. So this you have to provide. But once you've done that,

78
00:04:56,940 --> 00:04:59,430
then the rest of them all have default values.

79
00:04:59,430 --> 00:05:01,710
They already know how to behave and what to do

80
00:05:02,010 --> 00:05:05,850
even if you don't tell them anything extra. Now, however,

81
00:05:05,850 --> 00:05:08,640
if you wanted to modify one of those arguments,

82
00:05:08,700 --> 00:05:12,990
let's say I decide to change the font to something completely different

83
00:05:13,110 --> 00:05:18,110
like Times New Roman, and make the font super large

84
00:05:18,870 --> 00:05:22,710
80 size font and change it to bold,

85
00:05:23,220 --> 00:05:28,220
then you can see that that optional setting gets implemented and it's now

86
00:05:28,650 --> 00:05:32,490
changed the font and its changed the size and also made it bold.

87
00:05:33,120 --> 00:05:35,100
But this was completely

88
00:05:35,160 --> 00:05:36,510
optional.

89
00:05:37,470 --> 00:05:42,390
And this is all down to creating the function with default values.

