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