0:00:00.000,0:00:04.000 [Narrator] I hope you're getting a sense that lists are very powerful. 0:00:04.000,0:00:07.000 That by using mutation, by having lists that could contain other lists 0:00:07.000,0:00:10.000 or any other kind of data we want, 0:00:10.000,0:00:14.000 we can build very complex data structures, and we can do lots of interesting things. 0:00:14.000,0:00:16.000 I'm going to introduce 1 more list operation, 0:00:16.000,0:00:20.000 which will allow us to add a new element at the end of the list. 0:00:20.000,0:00:24.000 We've seen that we can use lists to store complex data, 0:00:24.000,0:00:27.000 that elements of the list can be any type we want including other lists, 0:00:27.000,0:00:30.000 and we've seen that we can use mutation to change the value of a list, 0:00:30.000,0:00:35.000 and that mutation is visible through any reference to the same list object. 0:00:35.000,0:00:39.000 Now I'm going to introduce some other list operations. 0:00:39.000,0:00:44.000 The first one is append, and append is like a procedure but it's a method, 0:00:44.000,0:00:47.000 so we use it similar to the way we use to find on strings. 0:00:47.000,0:00:52.000 We'll have a list first, then a dot followed by append, 0:00:52.000,0:00:55.000 and what we pass in is the element we want to append to the list. 0:00:55.000,0:00:59.000 Append will add a new element to the end of a list, 0:00:59.000,0:01:01.000 and the important thing about append is that it's mutating 0:01:01.000,0:01:04.000 the list that its invoked on. 0:01:04.000,0:01:08.000 It's not creating a new list; it's mutating the old list. 0:01:08.000,0:01:12.000 As an example of the use of append let's assume that instead of 0:01:12.000,0:01:16.000 replacing curly in the 3 stooges, we want to end up with 4 stooges. 0:01:16.000,0:01:19.000 We'll add Shemp and add the other 3 as they are. 0:01:19.000,0:01:24.000 So what we want to do is to append Shemp at the end of the list we have. 0:01:24.000,0:01:28.000 We would do that by invoking append on the stooges, 0:01:28.000,0:01:31.000 passing in the string Shemp as the input. 0:01:31.000,0:01:35.000 Here's what happens after the first assignment, 0:01:35.000,0:01:39.000 the name stooges refers to the list containing the 3 elements, 0:01:39.000,0:01:41.000 Moe, Larry, and Curly. 0:01:41.000,0:01:46.000 When we invoke append it modifies that object, 0:01:46.000,0:01:48.000 adding a new element to it. 0:01:48.000,0:01:54.000 After the append, the list that stooges refers to now has 4 elements. 0:01:54.000,0:01:56.000 We have not created a new list. 0:01:56.000,0:01:59.000 Note that there's no assignment from the result of append. 0:01:59.000,0:02:03.000 What we've done is modify the value that stooges refers to 0:02:03.000,0:02:06.000 by adding a new element to it.