1
00:00:04,120 --> 00:00:09,820
So let's go back now, to our Mutable
Sequence Types Python documentation page,

2
00:00:09,820 --> 00:00:14,690
and looking at that, it might look quite
confusing. The first five operations are

3
00:00:14,690 --> 00:00:19,759
using indexing and slicing, to change
items in the sequence. Make sure that

4
00:00:19,759 --> 00:00:24,050
you're happy using indexes and slices.
Review the videos in section 3, if

5
00:00:24,050 --> 00:00:29,000
necessary, because we'll be using slices
later in this section. I'm not going to

6
00:00:29,000 --> 00:00:32,540
discuss them just yet,
because changing slices will be easier

7
00:00:32,540 --> 00:00:36,890
to understand, once we've seen lists in
more detail. So I'm going to start by

8
00:00:36,890 --> 00:00:43,200
discussing the append method, which is
that sixth line, here in that table.

9
00:00:43,200 --> 00:00:48,520
Now I used the term method there. A method is
the same as a function, except that it's

10
00:00:48,520 --> 00:00:54,360
bound to an object. That means we need an
object, in order to call the method.

11
00:00:54,360 --> 00:00:59,320
We've used a few functions in the last video: we used min and max, and the len function.

12
00:00:59,320 --> 00:01:04,040
When you call a function, you just type
its name, and provide any arguments in

13
00:01:04,040 --> 00:01:07,729
parentheses. For example, len, and even in parentheses,

14
00:01:07,729 --> 00:01:13,540
gives us the number of items in the list
called even. When we call a method,

15
00:01:13,540 --> 00:01:17,960
we tell it which object it's called on. In
other words, which object it should be

16
00:01:17,960 --> 00:01:22,610
using when it performs its function. For
example, the entry we're looking at, in

17
00:01:22,610 --> 00:01:28,640
the table, is s.append and x in
parentheses. So that means that we'll be

18
00:01:28,640 --> 00:01:35,210
appending x to a list called s. We pass x
as an argument, so that the method knows

19
00:01:35,210 --> 00:01:39,799
what to append, but we don't have to use
an argument to tell it which list to

20
00:01:39,799 --> 00:01:46,070
append to, because that comes at the
start, before the dot. Dot notation's used

21
00:01:46,070 --> 00:01:50,600
a lot in Object Oriented Programming, and
we'll learn more about in the OOP

22
00:01:50,600 --> 00:01:54,710
section of this course. Before we learn
how to write our own methods, we'll be

23
00:01:54,710 --> 00:01:59,420
using a lot of methods that Python's
built-in objects have. The syntax is

24
00:01:59,420 --> 00:02:04,280
simple. You start with the object you're
using, then a dot, then the name of the

25
00:02:04,280 --> 00:02:10,960
method. If the method needs arguments, you put them in parentheses after the method name.

26
00:02:10,960 --> 00:02:15,620
So we start with the name of an
object. The documentation uses s because

27
00:02:15,620 --> 00:02:20,599
it's talking about sequence types.
After the dot, we have the name of the

28
00:02:20,599 --> 00:02:26,060
method that we want to call, in this case,
append. If the method needs any arguments,

29
00:02:26,060 --> 00:02:30,500
they appear in parentheses after the
method name. The parentheses are still

30
00:02:30,500 --> 00:02:34,370
needed, even if there are no arguments.
That's the same as when you call a

31
00:02:34,370 --> 00:02:39,560
function. Alright, so back to the code now.
The append method can be used to add a

32
00:02:39,560 --> 00:02:44,750
new item to a list. Now we used append in
the mutable.py program that we've

33
00:02:44,750 --> 00:02:49,820
written previously, so let's go and open that
up - specifically down here, on line 21.

34
00:02:49,820 --> 00:02:54,920
That appended cream, in this case, to our
list. So run the program again, just so we

35
00:02:54,920 --> 00:03:01,069
can see what's happening. When the list
is printed on line 18, it contains seven

36
00:03:01,069 --> 00:03:05,900
items. Line 20 prints the message Adding
cream, to make it easier to see what's

37
00:03:05,900 --> 00:03:11,090
happening in the output, and line 21 uses
the append method to add cream to the

38
00:03:11,090 --> 00:03:16,790
end of the list. So moving on, on lines 22
and 23, when we print the list it now

39
00:03:16,790 --> 00:03:20,340
contains cream, and you can see that in
the output down the bottom of the screen.

40
00:03:20,340 --> 00:03:24,100
Alright, so we've seen what methods are.
They're functions that belong to an

41
00:03:24,109 --> 00:03:28,579
object. In this case, the append method
belongs to anything that's a mutable

42
00:03:28,579 --> 00:03:33,350
sequence type. We've also talked about
dot notation, which is used when you want

43
00:03:33,350 --> 00:03:37,579
to call an object's methods. In the next
video, we'll write a simple program to

44
00:03:37,579 --> 00:03:43,000
demonstrate using append on a list. See
you in the next video.

