1
00:00:04,740 --> 00:00:10,410
So let's talk about functions calling
functions. In the last video, I mentioned

2
00:00:10,410 --> 00:00:17,130
that we already had the code on line 18.
This was copied from the is palindrome

3
00:00:17,130 --> 00:00:22,170
function. When you find yourself copying
and pasting code, stop and think if there

4
00:00:22,170 --> 00:00:27,240
isn't a better way. Functions allow you
to reuse a block of code, without copying

5
00:00:27,240 --> 00:00:31,949
and pasting. In our case, we copied the
code from a function that we'd already

6
00:00:31,949 --> 00:00:35,910
written. It might not have been obvious
at the time, but we can just call our

7
00:00:35,910 --> 00:00:41,280
function instead. So what I mean is, line
18 can be replaced by a call to the is

8
00:00:41,280 --> 00:00:47,610
palindrome function. So what I'm going to
do is comment out line 18, and on line 19

9
00:00:47,610 --> 00:00:54,360
what I'm going to do, is just type return
is_palindrome, and in

10
00:00:54,360 --> 00:00:57,320
parentheses I'm going to put string.

11
00:00:57,320 --> 00:01:01,840
And it would help if I typed return correctly. Okay.

12
00:01:01,840 --> 00:01:06,670
Line 19 is now calling out is_palindrome
function, then returns whatever value

13
00:01:06,670 --> 00:01:10,900
that returns. We've already tested the is
palindrome function and we know that it

14
00:01:10,900 --> 00:01:16,100
works. Using it with the palindrome
sentence function saves duplicating code.

15
00:01:16,100 --> 00:01:20,200
Of course, our testing has been quite
basic, but it's quite a simple function.

16
00:01:20,200 --> 00:01:24,460
We'll talk more about testing, later in
the course. That's another reason why

17
00:01:24,460 --> 00:01:28,630
calling the is_palindrome function is
a good idea. If we hadn't already noticed

18
00:01:28,630 --> 00:01:33,670
and fixed the uppercase bug, we'd have a
bug in two places. We'd need to add calls

19
00:01:33,670 --> 00:01:38,590
to .casefold on line 9, right at
the top of the screen there, and also on

20
00:01:38,590 --> 00:01:43,480
the old line 18 that I've now commented
out. But with the change we've just made,

21
00:01:43,480 --> 00:01:49,790
the bug only needs fixing in one place,
inside the is_palindrome function.

22
00:01:49,790 --> 00:01:53,150
So just to be clear, your functions can
call other functions that you've written.

23
00:01:53,150 --> 00:01:58,220
You're not restricted to just calling
the built-in Python functions. Alright,

24
00:01:58,220 --> 00:02:01,400
so let's end the video here, and in the
next one we'll look at the return

25
00:02:01,400 --> 00:02:06,760
keyword in more detail. See you in the
next video.

