1 00:00:00,920 --> 00:00:01,580 Welcome back. 2 00:00:02,210 --> 00:00:09,400 So far, we've learned a few built in functions that Python has few built in actions, right. 3 00:00:09,440 --> 00:00:11,110 Actions that we can take on data. 4 00:00:11,540 --> 00:00:13,310 And we learned about SDR. 5 00:00:13,820 --> 00:00:15,620 We learned about it. 6 00:00:16,340 --> 00:00:20,190 We learned about float and the type conversion that we can do. 7 00:00:20,720 --> 00:00:22,610 We also learned about type. 8 00:00:22,910 --> 00:00:28,490 We also learned about print and these built-In functions in Python. 9 00:00:28,700 --> 00:00:34,700 Well, there's a few of them and I'll link to this resource, but there's not too too many. 10 00:00:35,090 --> 00:00:40,760 As a matter of fact, we've also seen ones like ABB's or round. 11 00:00:42,200 --> 00:00:44,480 In our numbers video. 12 00:00:46,070 --> 00:00:55,250 So numbers had some functions that we can use, some built in functions well, string's also has a very 13 00:00:55,250 --> 00:01:02,030 useful one called Lente, which stands for LENTH, so as you guessed it. 14 00:01:03,430 --> 00:01:07,180 If I type in something like this and I print this out. 15 00:01:08,930 --> 00:01:15,560 And I click, run, I get nine because it's calculating the length of the strength in our case one, 16 00:01:16,430 --> 00:01:25,290 two, three, four, five, six, seven, eight, nine, the length of the string is nine. 17 00:01:25,940 --> 00:01:31,760 Now, you have to be careful here because the length itself doesn't start at zero, as we've seen with 18 00:01:31,760 --> 00:01:32,450 indexes. 19 00:01:32,480 --> 00:01:35,100 Instead, it counts like humans do from one. 20 00:01:35,930 --> 00:01:40,460 So a neat thing to do here is I can do something like this. 21 00:01:41,990 --> 00:01:47,150 Let's say that we have a variable greed that equals halloo. 22 00:01:49,090 --> 00:01:52,240 Well, I can grab the Grete. 23 00:01:54,230 --> 00:02:03,350 Variable, which is a string and use string slicing to grab well, the first and then go all the way 24 00:02:03,350 --> 00:02:04,190 until the end. 25 00:02:04,550 --> 00:02:06,530 Now, the default already does this. 26 00:02:06,690 --> 00:02:13,600 If I leave it like this, it's going to grab hello and make sure I add a bracket here. 27 00:02:13,640 --> 00:02:14,360 Let's click run. 28 00:02:15,020 --> 00:02:15,890 I get hello. 29 00:02:17,410 --> 00:02:21,730 Now, if I do zero to length of. 30 00:02:24,990 --> 00:02:25,770 What does that mean? 31 00:02:25,830 --> 00:02:31,110 Well, if I click run, I still get hello because the length of Grete. 32 00:02:32,270 --> 00:02:33,770 Is nine. 33 00:02:37,010 --> 00:02:45,500 Like, so now this lenth function is quite useful and we're going to use it a lot in this course, but 34 00:02:45,500 --> 00:02:48,650 I want to introduce to you the concept of built in functions. 35 00:02:49,920 --> 00:02:56,250 As well as what we call builtin methods, hmm, what does that mean? 36 00:02:57,320 --> 00:03:04,040 A built in function had the syntax of the word that was highlighted in blue, and then we used curly 37 00:03:04,040 --> 00:03:09,900 brackets to perform some action on a data type. 38 00:03:10,730 --> 00:03:17,960 However, Python also has this idea of methods and methods are similar to functions, but they they 39 00:03:17,960 --> 00:03:20,270 are owned by something. 40 00:03:20,840 --> 00:03:25,310 So, for example, in Python, we have string methods. 41 00:03:25,670 --> 00:03:31,300 So these are methods or actions that only strings can perform. 42 00:03:31,640 --> 00:03:32,450 And don't worry. 43 00:03:32,600 --> 00:03:36,980 This is something that we'll talk more about when we talk about classes and functions. 44 00:03:37,850 --> 00:03:41,660 But for now, Python, for example, has a string methods. 45 00:03:41,990 --> 00:03:50,030 So these are methods that we can use specifically for strings and methods, have a special syntax where 46 00:03:50,030 --> 00:03:55,730 instead of just the word with the curly brackets, it usually has a dot in front of it. 47 00:03:56,030 --> 00:03:59,360 So dot and then some sort of word. 48 00:03:59,360 --> 00:04:02,120 And we've actually seen one format, right? 49 00:04:02,510 --> 00:04:07,340 DOT format, curly brackets or brackets is a method. 50 00:04:07,490 --> 00:04:14,360 And if I go to Python string methods and I scroll down or scroll up, we see that format, format, 51 00:04:14,360 --> 00:04:17,390 specific values and a string is a method. 52 00:04:18,650 --> 00:04:20,150 Now, why do we care? 53 00:04:20,870 --> 00:04:21,200 Well. 54 00:04:22,330 --> 00:04:29,620 With this, python gives us automatic tools that we can use on strength, so let's explore some of these 55 00:04:29,740 --> 00:04:30,910 string methods. 56 00:04:32,330 --> 00:04:38,720 Let's create a quote here, and the quote is going to be to be or not to be. 57 00:04:40,930 --> 00:04:48,940 Now, in here with this quote, We can use some methods on this string now I'm not going to go through 58 00:04:48,940 --> 00:04:54,760 everything because, well, 60 percent of these you're most likely never going to use in your career. 59 00:04:55,390 --> 00:04:58,630 I'm going to go over the important ones that you'll see over and over again. 60 00:04:58,750 --> 00:05:02,350 But I'll also link to this so that you can see this for yourself as a reference. 61 00:05:02,530 --> 00:05:09,250 Remember, as a programmer, your job is not to memorize this and read a language like you read a dictionary 62 00:05:09,370 --> 00:05:17,800 instead is to know that this resource exists and it's for you to explore and learn as a specific problem 63 00:05:17,800 --> 00:05:18,260 occurs. 64 00:05:18,820 --> 00:05:20,920 But let's get back to the task at hand. 65 00:05:22,620 --> 00:05:33,120 One thing that we can do is to use the upper method, we use a dot and then type in upper and then the 66 00:05:33,120 --> 00:05:33,960 curly brackets. 67 00:05:34,170 --> 00:05:41,050 And luckily for us, our Ed shows us that this actually exists because of the drop down menu. 68 00:05:41,610 --> 00:05:44,760 So what happens now if I print this? 69 00:05:50,140 --> 00:05:54,370 Look at that, everything gets capitalized to be or not to be. 70 00:05:56,540 --> 00:06:01,910 There is also another one we can use called Capitalize. 71 00:06:02,880 --> 00:06:04,320 What's the difference between the two? 72 00:06:05,610 --> 00:06:11,880 Well, if I run, you see that it capitalizes the beginning of the sentence. 73 00:06:13,400 --> 00:06:18,620 And by the way, your editor or in our case, our Reppel, if you hover over this, will actually tell 74 00:06:18,620 --> 00:06:20,450 you what it does. 75 00:06:21,740 --> 00:06:24,740 It returns a capitalized version of S.. 76 00:06:26,260 --> 00:06:28,330 So whatever is to the left of the. 77 00:06:30,330 --> 00:06:37,140 And a good editor will actually show you all the things available to you, so as soon as you press a 78 00:06:37,140 --> 00:06:45,240 dot, look at that, I see all these purple boxes, which are methods that are available to me for a 79 00:06:45,270 --> 00:06:45,660 string. 80 00:06:45,960 --> 00:06:47,900 And you see there's a lot of them. 81 00:06:48,660 --> 00:06:54,660 Now, don't worry about these double underscores these Dundar methods, because this is something that 82 00:06:54,660 --> 00:06:56,550 we'll talk about when we talk about classes. 83 00:06:56,880 --> 00:06:59,910 But you can see that you have different things that you can use. 84 00:07:01,160 --> 00:07:05,660 For example, you have lower instead of upper and lower cases, everything. 85 00:07:07,850 --> 00:07:10,670 What if I want to use find, for example? 86 00:07:11,870 --> 00:07:21,290 And Fine simply says, hey, does B exist in the code to be or not to be, in fact, like run? 87 00:07:22,550 --> 00:07:30,500 Well, it tells me that, yes, I could not find has a B and it starts at index of three. 88 00:07:31,620 --> 00:07:40,440 So if I go to zero one, two and then look at that three, so we have to find which finds us the first 89 00:07:40,440 --> 00:07:43,530 occurrence of a piece of text. 90 00:07:45,120 --> 00:07:53,400 You also have things like replace where I can replace whatever I give it as the first thing and then 91 00:07:53,400 --> 00:07:55,290 separate it to the second thing. 92 00:07:55,650 --> 00:08:04,260 So you can see over here, it tells me old and then comma new and I can replace this with me if I click 93 00:08:04,260 --> 00:08:04,620 run. 94 00:08:05,530 --> 00:08:14,110 I get to me or not to me, so this replaces all the occurrences of the now the final thing I want to 95 00:08:14,110 --> 00:08:22,750 point out to you is that if I print here, quote, what do you think is going to happen? 96 00:08:23,260 --> 00:08:29,410 I've printed here and I replaced to me to be or not to be with. 97 00:08:29,410 --> 00:08:30,640 To me or not to me. 98 00:08:31,870 --> 00:08:38,170 Quite a selfish quote, but if I print this again on the fifth line, what do you think will happen? 99 00:08:38,800 --> 00:08:39,330 Let's find out. 100 00:08:43,790 --> 00:08:45,350 Is this what you expected? 101 00:08:46,450 --> 00:08:49,600 Think about why this might happen based on what we've learned. 102 00:08:51,150 --> 00:08:57,070 Here's the thing, remember, strings are immutable, that is they cannot be changed. 103 00:08:57,120 --> 00:09:01,200 We can overwrite them if we want, but we don't change them. 104 00:09:01,470 --> 00:09:03,330 We either create them or destroy them. 105 00:09:03,660 --> 00:09:12,090 In our case, when we do, quote, replace to me or not to me, it's creating a new string. 106 00:09:13,070 --> 00:09:19,730 Now, we're not assigning the string to anything, so eventually after we printed, we remove it from 107 00:09:19,730 --> 00:09:20,150 memory. 108 00:09:20,630 --> 00:09:22,460 But if I do something like. 109 00:09:23,900 --> 00:09:25,790 This where I have. 110 00:09:26,580 --> 00:09:34,050 Quote, two equals, quote, I replace and I print quote to. 111 00:09:36,120 --> 00:09:42,990 Well, in our case, we're creating a whole new string, we're creating a string, but we never modify 112 00:09:43,290 --> 00:09:45,660 the original string because it's immutable. 113 00:09:46,200 --> 00:09:52,500 So that quote always stays the way it is until we destroy it. 114 00:09:52,500 --> 00:09:54,010 Until we remove it. 115 00:09:54,030 --> 00:09:55,140 Our program ends. 116 00:09:55,410 --> 00:09:57,000 This is going to exist. 117 00:09:59,530 --> 00:10:03,250 Hope you're having fun, hang in there more to learn in the next video.