1 00:00:01,140 --> 00:00:02,580 Narrator: So up until now, 2 00:00:02,580 --> 00:00:07,500 we learned that strings can be accessed quite easily. 3 00:00:07,500 --> 00:00:09,210 And using the square brackets, 4 00:00:09,210 --> 00:00:12,300 we can access different parts of the string. 5 00:00:12,300 --> 00:00:14,570 And this idea of a start, 6 00:00:14,570 --> 00:00:16,200 a stop, 7 00:00:16,200 --> 00:00:18,366 and a step over 8 00:00:18,366 --> 00:00:22,140 is what we call slicing or string slicing, 9 00:00:22,140 --> 00:00:25,653 because we can slice the string however we like. 10 00:00:26,490 --> 00:00:29,040 But we also need to learn another important term 11 00:00:29,040 --> 00:00:32,159 that's gonna come up again and again throughout this course. 12 00:00:32,159 --> 00:00:34,403 And as a matter of fact, it's an important concept that 13 00:00:34,403 --> 00:00:37,200 as you get more advanced into programming, 14 00:00:37,200 --> 00:00:39,390 you really need to understand. 15 00:00:39,390 --> 00:00:41,280 what is this concept? 16 00:00:41,280 --> 00:00:44,700 Well, it's this idea of immutability. 17 00:00:44,700 --> 00:00:47,403 It's an important term in programming. 18 00:00:48,630 --> 00:00:51,513 What does immutability mean? 19 00:00:52,560 --> 00:00:55,500 Well, strings in Python are immutable. 20 00:00:55,500 --> 00:00:58,320 That means they cannot be changed. 21 00:00:58,320 --> 00:01:00,300 What do I mean by that? 22 00:01:00,300 --> 00:01:04,590 Now that we've assigned selfish this value 23 00:01:04,590 --> 00:01:06,540 this string, 24 00:01:06,540 --> 00:01:07,650 well... 25 00:01:07,650 --> 00:01:09,450 I can reassign it, right? 26 00:01:09,450 --> 00:01:11,733 I can say selfish is 100 now, 27 00:01:12,685 --> 00:01:15,460 and if I print selfish 28 00:01:17,076 --> 00:01:20,550 and I click run, that works. 29 00:01:20,550 --> 00:01:23,880 But if I instead do something like 30 00:01:23,880 --> 00:01:28,880 the first index of selfish is going to equal eight, 31 00:01:29,400 --> 00:01:30,820 and I click run 32 00:01:31,830 --> 00:01:32,808 I get an error. 33 00:01:32,808 --> 00:01:34,500 I get a type error saying, 34 00:01:34,500 --> 00:01:37,863 String object does not support item assignment. 35 00:01:38,790 --> 00:01:39,960 Why is that? 36 00:01:39,960 --> 00:01:42,483 Because strings are immutable. 37 00:01:43,320 --> 00:01:45,776 That is, I cannot change 38 00:01:45,776 --> 00:01:47,640 the value of this 39 00:01:47,640 --> 00:01:49,023 once it's created. 40 00:01:50,160 --> 00:01:54,030 I can't just immediately change it to 8, 1-2-3-4-5-6-7. 41 00:01:54,030 --> 00:01:56,490 Nope, it has to stay the same. 42 00:01:56,490 --> 00:02:00,330 The only way that I can remove this or change this 43 00:02:00,330 --> 00:02:03,183 is to completely reassign the value. 44 00:02:04,800 --> 00:02:06,639 So that in memory, 45 00:02:06,639 --> 00:02:10,949 Python removes all of this from our bookshelf of memory 46 00:02:10,949 --> 00:02:15,570 and instead just assigns eight into the zero bookshelf 47 00:02:15,570 --> 00:02:18,570 and removes everything else because we don't use it anymore. 48 00:02:19,860 --> 00:02:22,572 Now, this idea of immutability 49 00:02:22,572 --> 00:02:25,169 is something we'll explore more and more, 50 00:02:25,169 --> 00:02:28,530 especially when we start talking about lists. 51 00:02:28,530 --> 00:02:30,300 But for now, just remember 52 00:02:30,300 --> 00:02:34,590 that you can't reassign part of a string. 53 00:02:34,590 --> 00:02:38,730 Once created, it exists like that in that form. 54 00:02:38,730 --> 00:02:42,720 The only way we can change it is to create something new. 55 00:02:42,720 --> 00:02:46,500 We can do selfish plus eight, 56 00:02:46,500 --> 00:02:48,930 and we can create it that way. 57 00:02:48,930 --> 00:02:53,370 But now this selfish is a whole new string. 58 00:02:53,370 --> 00:02:56,490 This no longer exists, 59 00:02:56,490 --> 00:03:00,060 and a whole new shelf space was created 60 00:03:00,060 --> 00:03:02,613 for us to use this whole new string. 61 00:03:03,870 --> 00:03:06,390 Again, if this doesn't make sense to you 62 00:03:06,390 --> 00:03:09,034 or why it's important just yet, don't worry. 63 00:03:09,034 --> 00:03:10,530 We'll get there. 64 00:03:10,530 --> 00:03:12,810 For now though, I'll see you in the next video. 65 00:03:12,810 --> 00:03:13,643 Bye bye.