1
00:00:05,359 --> 00:00:07,839
We're nearly finished with all
the new stuff in this section.

2
00:00:07,839 --> 00:00:12,320
In this video, we'll see how to annotate
parameters that have default values.

3
00:00:12,320 --> 00:00:16,239
We're going to use banner.py for this
example, and add annotations to the

4
00:00:16,239 --> 00:00:23,620
banner_text function.
So let's open up banner.py,

5
00:00:23,620 --> 00:00:27,199
specifically, our banner_text function.
So before I start,

6
00:00:27,199 --> 00:00:31,039
remember that we don't put spaces around
the equal sign, when providing a default

7
00:00:31,039 --> 00:00:33,520
parameter value.
On line 1, you can see there's no

8
00:00:33,520 --> 00:00:38,480
spaces around the two equal signs,
but that changes if we annotate the

9
00:00:38,480 --> 00:00:40,719
parameters. So let me go ahead and do that.

10
00:00:40,719 --> 00:00:47,120
I'm going to put text colon
str, and if we add a space before the

11
00:00:47,120 --> 00:00:49,840
equal and after sign now,
and for screen width, we're going to put

12
00:00:49,840 --> 00:00:55,840
screen width colon int, 
with a space there, equals 80.

13
00:00:55,840 --> 00:00:58,480
And noticing, I'm putting
a space around both now.

14
00:00:58,480 --> 00:01:02,640
Our function is defined as taking one
parameter of type str string,

15
00:01:02,640 --> 00:01:05,920
the default value of space, and a second
parameter of type

16
00:01:05,920 --> 00:01:10,720
int, with a default value of 80.
When we add the annotations we should,

17
00:01:10,720 --> 00:01:14,240
now, put spaces around
the equal signs. So just to clarify,

18
00:01:14,240 --> 00:01:18,000
this convention is described in PEP 8.

19
00:01:21,360 --> 00:01:24,640
Now rather than reading through the
whole document, search for default value

20
00:01:24,640 --> 00:01:28,640
to get to the relevant section.
So I'll do that now.

21
00:01:34,560 --> 00:01:38,079
So there's a few examples of
correct and wrong here.

22
00:01:38,079 --> 00:01:42,640
Close down the search now. And you'll
find here, the recommendation which says,

23
00:01:42,640 --> 00:01:47,280
when combining an argument annotation
with a default value, however, do use

24
00:01:47,280 --> 00:01:50,799
spaces around the equal sign.
You're well on the way to understanding

25
00:01:50,799 --> 00:01:54,880
everything in this document. The sections
discussing classes and comprehensions

26
00:01:54,880 --> 00:01:58,399
won't be completely understandable yet,
but most of the rest of it should now

27
00:01:58,399 --> 00:02:02,880
make sense. So going back to our code,
I'm going to click on the call to

28
00:02:02,880 --> 00:02:08,318
banner_text on line 14.
Use Ctrl Q. Now that I've called up the

29
00:02:08,318 --> 00:02:10,720
documentation, you can see
that it's neatly formatted,

30
00:02:10,720 --> 00:02:14,800
with the types and default values
showing. The return value

31
00:02:14,800 --> 00:02:18,560
isn't quite right, though. It's saying
that the function returns Any.

32
00:02:18,560 --> 00:02:22,720
Any, when used in a function annotation,
is used for functions that can return a

33
00:02:22,720 --> 00:02:26,319
range of different types.
It's not appropriate here, because this

34
00:02:26,319 --> 00:02:29,120
function isn't intended to return a value.

35
00:02:29,120 --> 00:02:32,000
To make that clear, we annotate the
return value as None, so let's come up

36
00:02:32,000 --> 00:02:35,519
here and do that.
Using the arrow again, the dash and the

37
00:02:35,520 --> 00:02:41,020
greater than sign,
None - capital n before the colon.

38
00:02:41,020 --> 00:02:43,760
Calling up the documentation again,
this time I'll just hover over it.

39
00:02:43,760 --> 00:02:47,360
You can see it's now correct,
returning None.

40
00:02:47,360 --> 00:02:51,120
So if you annotate any part of a
function definition, you should annotate

41
00:02:51,120 --> 00:02:54,879
all of it - either all parameters and the
return value should be annotated,

42
00:02:54,880 --> 00:03:01,360
or don't use any annotation. Alright, so
I'll finish this video with a mini challenge.

43
00:03:28,560 --> 00:03:33,200
See you in the next video.

