1
00:00:05,930 --> 00:00:12,690
Welcome back everyone to this lecture on strings strings are sequences of characters and the syntax

2
00:00:12,720 --> 00:00:15,150
of either single quotes or double quotes.

3
00:00:15,150 --> 00:00:19,320
So here we have a couple of string examples the first one uses single quotes of Hello.

4
00:00:19,350 --> 00:00:21,450
The second one uses double quotes of Hello.

5
00:00:21,600 --> 00:00:22,430
And the third one.

6
00:00:22,440 --> 00:00:23,880
Notice what's happening here.

7
00:00:23,880 --> 00:00:26,300
We have a single quote already inside the string.

8
00:00:26,340 --> 00:00:27,720
I don't do that.

9
00:00:27,750 --> 00:00:32,370
So in order to make sure your string doesn't prematurely stop with the single quote inside of don't

10
00:00:32,630 --> 00:00:36,000
what we do is we add two double quotes and block it off.

11
00:00:36,090 --> 00:00:40,150
That way we can understand with Python that we don't want the strings and at don't.

12
00:00:40,170 --> 00:00:42,460
Instead we can wrap it in the other quote tight.

13
00:00:42,570 --> 00:00:45,370
So that's why we have the use of both single and double quotes.

14
00:00:45,480 --> 00:00:50,400
If one of your double quotes or some quotes is planning to be inside of your string you just wrap it

15
00:00:50,400 --> 00:00:56,920
again and the other quote type Now more importantly because strings are ordered sequences.

16
00:00:56,920 --> 00:01:02,930
It means we can use indexing and slicing to grab subsections of the string indexing notation.

17
00:01:02,950 --> 00:01:08,860
Use a square bracket notation after the string or after the variable assigned the string indexing allows

18
00:01:08,860 --> 00:01:10,990
you to grab a single character from the string.

19
00:01:10,990 --> 00:01:12,010
So what does that actually mean.

20
00:01:12,010 --> 00:01:13,240
Let's see some examples of that.

21
00:01:14,820 --> 00:01:19,560
So again those indexing actions and the slicing actions are going to use square brackets notation and

22
00:01:19,560 --> 00:01:25,170
we do as you pass in a number index instead of the square brackets to indicate the positions of what

23
00:01:25,170 --> 00:01:26,090
you want to grab.

24
00:01:26,340 --> 00:01:31,980
So here I have the string hello and now I have a corresponding index for each of these characters.

25
00:01:32,010 --> 00:01:39,560
So zero goes of H one goes if e to the first L three at the fourth L or second L and then for the Oh.

26
00:01:39,870 --> 00:01:43,180
So there we have hello and if I want to grab back the letter H.

27
00:01:43,180 --> 00:01:46,610
All I need to do is pass an 0 into the square brackets.

28
00:01:46,650 --> 00:01:52,500
Keep in mind Python also has the ability to do a reverse indexing so we can go starting at age 0 and

29
00:01:52,500 --> 00:01:55,370
then go all the way to the end of the string and that's negative one.

30
00:01:55,390 --> 00:01:56,350
Then we have it too.

31
00:01:56,370 --> 00:01:57,510
And so on.

32
00:01:57,510 --> 00:02:03,630
So reverse indexing is really useful when you may not know the string length and you want to grab maybe

33
00:02:03,630 --> 00:02:05,210
the last character string.

34
00:02:05,340 --> 00:02:09,990
For example if someone's registering for a web site and they provide a user name and the user name is

35
00:02:09,990 --> 00:02:11,360
not going to be known beforehand.

36
00:02:11,550 --> 00:02:15,750
And for whatever reason you wanted to grab the last letter of the username instead of trying to guess

37
00:02:15,750 --> 00:02:21,090
the index position of the very last letter where you could do is just pass a negative one and that will

38
00:02:21,150 --> 00:02:22,670
automatically grab the last letter.

39
00:02:22,740 --> 00:02:25,650
Regardless of how long the string is.

40
00:02:25,830 --> 00:02:29,940
So that's indexing which allows you to grab a single character element from the string.

41
00:02:29,940 --> 00:02:35,370
Slicing allows you to grab a subsection of multiple characters otherwise known as a slice of the string.

42
00:02:35,730 --> 00:02:38,010
So slicing has the following syntax.

43
00:02:38,100 --> 00:02:43,630
You start with square brackets and then you have a start colon a stop colon and then this step.

44
00:02:43,650 --> 00:02:50,170
So start as a numerical index for the slice start stop is the index you're going to go up to but not

45
00:02:50,170 --> 00:02:55,840
include and then step is the size of the jump you're going to take between start and stop.

46
00:02:56,050 --> 00:02:56,340
OK.

47
00:02:56,350 --> 00:02:59,280
So that's going to be more clear when we actually work through those examples.

48
00:03:00,010 --> 00:03:05,980
For now let's go to Adam and explore these concepts overcoached strings indexing strings slicing strings.

49
00:03:05,980 --> 00:03:10,810
And then we'll also talk about string properties methods and how we can't print format variables inside

50
00:03:10,810 --> 00:03:11,820
of her own strings.

51
00:03:11,950 --> 00:03:13,700
What to cover so let's get started.

52
00:03:13,960 --> 00:03:18,520
OK here I am back at home and I have my exampled up my file open.

53
00:03:18,520 --> 00:03:20,140
Let's go and just type out a string.

54
00:03:20,320 --> 00:03:21,070
Hello.

55
00:03:21,430 --> 00:03:27,730
And again notice what's happening if I run this python my example that pi actually doesn't get any output

56
00:03:28,060 --> 00:03:29,580
in order to see the output.

57
00:03:29,710 --> 00:03:31,100
I'm going to need to print this out.

58
00:03:31,350 --> 00:03:37,780
So say a print and then pass in the string you want to print hello with double quotes or single quotes

59
00:03:37,870 --> 00:03:39,790
and then we see Hello as the output.

60
00:03:39,790 --> 00:03:42,690
So keep that in mind as you're working if not postscripts.

61
00:03:42,700 --> 00:03:43,500
It's easy to forget.

62
00:03:43,510 --> 00:03:47,350
They need to print things out in order to see them as output at your command line.

63
00:03:47,740 --> 00:03:49,870
So that's the basics of printing a string.

64
00:03:50,080 --> 00:03:54,500
I also want to show you a really useful function called Alien which checks the length of a string.

65
00:03:54,660 --> 00:03:57,890
And we'll also see how it's able to check the length of many object types.

66
00:03:58,030 --> 00:04:03,900
But if you want to know the length of the string you just passing that string inside of the end function.

67
00:04:05,290 --> 00:04:07,020
So I pass in Hello.

68
00:04:07,180 --> 00:04:10,480
Inside the length of this function and then print out the result.

69
00:04:10,480 --> 00:04:13,410
Now tell me how many characters are inside of this string.

70
00:04:13,420 --> 00:04:14,750
In my case it's 5.

71
00:04:14,890 --> 00:04:16,920
So 0 1 2 3 4 5.

72
00:04:17,110 --> 00:04:19,420
You should know it's going to count spaces as well.

73
00:04:19,630 --> 00:04:24,300
So if I add in three spaces there and then run this it's now going to report 8.

74
00:04:24,430 --> 00:04:28,490
Because these three spaces also count as part of that sequence of characters.

75
00:04:28,760 --> 00:04:29,150
OK.

76
00:04:29,410 --> 00:04:32,550
So that's printing out a string and that's checking the length of a string.

77
00:04:32,770 --> 00:04:34,460
Let's talk about indexing now.

78
00:04:35,560 --> 00:04:37,510
I'm going to start for variable assignment.

79
00:04:37,930 --> 00:04:42,240
I'll see my string is equal to hello.

80
00:04:42,600 --> 00:04:47,730
And then I want to get it to do is let's imagine I wanted to print out the first letter of the string.

81
00:04:47,730 --> 00:04:54,000
What I would do is say my string and then I have this square bracket notation for indexing you pass

82
00:04:54,090 --> 00:04:57,360
in the index number of whatever character you want.

83
00:04:57,360 --> 00:04:58,670
So if I want h.

84
00:04:58,710 --> 00:05:00,690
Remember that's going to start at zero.

85
00:05:00,720 --> 00:05:05,300
So then I pass an 0 here and then I can print out that result.

86
00:05:05,340 --> 00:05:10,400
So let's do that then a print out my string 0 run this.

87
00:05:10,530 --> 00:05:12,930
And now I get back in h over here.

88
00:05:12,930 --> 00:05:13,520
Let's imagine.

89
00:05:13,530 --> 00:05:14,280
I want it.

90
00:05:14,350 --> 00:05:18,160
E Well that's going to be 1 over so 0 1.

91
00:05:18,270 --> 00:05:22,740
So I just pass in one save that and when they run this I get back.

92
00:05:23,010 --> 00:05:24,070
Let's imagine I want it.

93
00:05:24,090 --> 00:05:25,980
Oh there's two ways I can do that.

94
00:05:25,980 --> 00:05:29,270
I could go 0 1 2 3 4.

95
00:05:29,430 --> 00:05:34,510
So capacity a four here save it run it and I would get back in 0.

96
00:05:34,740 --> 00:05:41,430
Or alternatively I could use negative indexing to say hey go to negative 1 essentially grab the last

97
00:05:41,430 --> 00:05:45,070
letter in that string and then that also gives it back.

98
00:05:45,260 --> 00:05:49,650
So that's indexing describing a single element or character from the string.

99
00:05:49,730 --> 00:05:52,040
The next thing I want to talk about is slicing.

100
00:05:52,040 --> 00:05:55,180
So we just talked about here was indexing.

101
00:05:55,190 --> 00:05:57,240
Now let's talk slicing a string.

102
00:05:57,240 --> 00:06:01,100
So in order to slice a string we're going to use a little bit of different syntax and I'm actually going

103
00:06:01,100 --> 00:06:07,510
to type in something like a b c d e f g h i j.

104
00:06:07,860 --> 00:06:10,700
There you are slicing and to be more obvious.

105
00:06:10,700 --> 00:06:14,660
So right now we know how to grab a single letter from the string but would have actually wanted to grab

106
00:06:14,660 --> 00:06:17,080
a slice of letters such as ABC.

107
00:06:17,390 --> 00:06:19,340
Oh what I could do is the following.

108
00:06:19,490 --> 00:06:25,230
I'll say my string and the syntax is going to be your start colon and then your stop.

109
00:06:25,250 --> 00:06:27,390
So let's imagine I want to grab ABC.

110
00:06:27,530 --> 00:06:33,590
That means I want to start at zero colon and then you're going to go stop up to the index you want to

111
00:06:33,590 --> 00:06:34,660
grab two.

112
00:06:34,670 --> 00:06:40,240
So I want to get a b c so that's 0 1 2.

113
00:06:40,430 --> 00:06:47,570
And the way Python works is you're going to go up to not including index position 3 to go 0 1 2 and

114
00:06:47,570 --> 00:06:53,950
then up to but not including three so that's important to know that the start position is inclusive

115
00:06:54,130 --> 00:06:57,150
and the end position or stop position is Xclusive.

116
00:06:57,280 --> 00:07:00,190
So that sometimes confuses a beginner so just keep that in mind.

117
00:07:00,210 --> 00:07:05,080
I'm going to print out the results of this and it's go all the way to the end.

118
00:07:05,080 --> 00:07:08,880
Close off that parentheses run this.

119
00:07:09,050 --> 00:07:16,660
And now I get back a b c Let's explore for another example let's imagine I want to grab the F G what

120
00:07:16,710 --> 00:07:19,520
I'm going to do is figure out where I'm going to start.

121
00:07:19,520 --> 00:07:23,230
So start is inclusive starting to go 0 1 2 3 4.

122
00:07:23,390 --> 00:07:24,540
So there's that e.

123
00:07:24,680 --> 00:07:26,610
So say for colon.

124
00:07:26,630 --> 00:07:36,220
And then I want to go grab F.G. up to and including index h 0 1 2 3 4 5 6 7.

125
00:07:36,220 --> 00:07:37,950
There we go for seven.

126
00:07:37,970 --> 00:07:39,970
And let's see if that grass is f g.

127
00:07:40,220 --> 00:07:43,070
We run it and there we go F G again.

128
00:07:43,160 --> 00:07:45,620
Careful note here on the stop index.

129
00:07:45,670 --> 00:07:49,870
It's again going up to but not including that top index is included.

130
00:07:49,880 --> 00:07:51,740
Stop goes up to and not including it.

131
00:07:51,830 --> 00:07:55,770
That's a really common point for beginners to kind of get confused by.

132
00:07:55,780 --> 00:08:00,530
Now I also want to show you that it can add in the step size here so for.

133
00:08:00,680 --> 00:08:04,630
Let's go from 0 up to let's say G.

134
00:08:04,670 --> 00:08:06,490
So we go from 0 to 7.

135
00:08:06,950 --> 00:08:10,910
So if I run that that gives me back ABC D E F G.

136
00:08:11,210 --> 00:08:17,540
But let's add in a third parameter here and I say colon again and then pasand to remember goes.

137
00:08:17,540 --> 00:08:21,300
Start Colan stop colon step.

138
00:08:21,380 --> 00:08:26,500
So now that I have that what it's going to do is by default it takes a step size of one goes a then

139
00:08:26,500 --> 00:08:32,900
one over B than one over see if I pass and two as it's third parameter it's going to go a go to over

140
00:08:32,900 --> 00:08:35,760
to see go to over to E and so on.

141
00:08:36,020 --> 00:08:42,950
So then when I print out this result I get back a C E G again it's going in step size of two and you

142
00:08:42,950 --> 00:08:47,250
can play around with the step size to keep making larger and larger jumps.

143
00:08:47,300 --> 00:08:50,500
So they want to make a jumps or steps or three because a.

144
00:08:50,660 --> 00:08:51,440
One two three.

145
00:08:51,440 --> 00:08:54,410
The one two three to G and so on.

146
00:08:54,410 --> 00:08:54,840
OK.

147
00:08:55,070 --> 00:09:00,590
So that's the start the stop and the step size now because it's so common to start at the very beginning

148
00:09:00,590 --> 00:09:08,450
of a string let's go back here to this example 0 7 which gives us everything up to this sort of command

149
00:09:08,510 --> 00:09:09,440
is really common.

150
00:09:09,440 --> 00:09:14,150
Starting at the beginning of a string and then going all the way to some index that you can actually

151
00:09:14,540 --> 00:09:17,120
if you remove 0 it will default to zero.

152
00:09:17,120 --> 00:09:21,620
So if say colon and some number that's going to say starting at the beginning of the string go all the

153
00:09:21,620 --> 00:09:23,910
way up to but not including that index.

154
00:09:23,990 --> 00:09:27,810
So running that is going to get you ABC the BFG.

155
00:09:27,830 --> 00:09:30,920
Now just like starting from the very beginning.

156
00:09:30,950 --> 00:09:33,380
You can also say go all the way to the end.

157
00:09:33,380 --> 00:09:39,600
So if you put a number down and then type in a colon that's going to say starting in Expedition 7.

158
00:09:39,620 --> 00:09:43,840
Give me the string all the way to the end so that you get IGY.

159
00:09:43,880 --> 00:09:48,110
So this one is pretty nice that you don't need a count over what the last index position of the string

160
00:09:48,110 --> 00:09:48,420
is.

161
00:09:48,470 --> 00:09:54,800
So you say start here colon go all the way to the end and the opposite is colon start at the very beginning

162
00:09:54,920 --> 00:09:57,710
and go all the way to this particular index position.

163
00:09:58,100 --> 00:09:59,040
OK.

164
00:09:59,090 --> 00:10:04,790
Now the last thing I want to know which is kind of interesting thing is if we say colon colon that means

165
00:10:04,790 --> 00:10:08,120
start from the very beginning and go all the way to the end.

166
00:10:08,120 --> 00:10:12,040
Now that by itself isn't really useful because it's basically just asking for the whole string back.

167
00:10:12,140 --> 00:10:16,820
But often what people like to do is they like to then add in the step parameter so that says starting

168
00:10:16,880 --> 00:10:21,720
all the way from the beginning going all the way to the end going to step size of two.

169
00:10:21,740 --> 00:10:27,600
So when I run that we should see a step size of two to see step size to eat and so on.

170
00:10:27,770 --> 00:10:32,390
All the way until we get to the end the string which in this case is going to be I given our step size.

171
00:10:32,720 --> 00:10:33,030
OK.

172
00:10:33,050 --> 00:10:36,680
So again colon colon start from the very beginning all the way to the end.

173
00:10:36,680 --> 00:10:38,340
And give me a step size or two.

174
00:10:38,600 --> 00:10:42,830
What's really interesting is that you can actually then use a reverse step size and we want to do this

175
00:10:42,830 --> 00:10:43,510
too often.

176
00:10:43,520 --> 00:10:48,110
Basically still in time we're going to show it but you can reverse the strain quite easily using something

177
00:10:48,110 --> 00:10:51,220
like start from the very beginning to the end.

178
00:10:51,350 --> 00:10:52,940
But give me is the size of negative one.

179
00:10:52,940 --> 00:10:56,720
So it's going to basically start here and then go backwards to J I h.

180
00:10:56,720 --> 00:10:57,520
And so on.

181
00:10:57,770 --> 00:11:03,370
So when you save it and run it you actually get the reverse of the string.

182
00:11:03,380 --> 00:11:06,920
So this is a really quick way to reverse a string in Python.

183
00:11:06,920 --> 00:11:11,300
Again won't be doing it too much in this course but just keep in mind that it's available to you.

184
00:11:11,300 --> 00:11:16,280
Finally I want to talk about some string properties and string methods as well as how we can use what's

185
00:11:16,280 --> 00:11:19,130
known as string interpellation to print out strings.

186
00:11:19,130 --> 00:11:20,660
So we talking about indexing and slicing.

187
00:11:20,660 --> 00:11:21,920
Very important things.

188
00:11:21,950 --> 00:11:25,420
I also want to talk about the fact that strings are immutable.

189
00:11:25,550 --> 00:11:32,530
Meaning if I wanted to change the character here a to z what it cannot do is I cannot do the following.

190
00:11:32,540 --> 00:11:36,530
I can't say hey my stream index position zero.

191
00:11:36,590 --> 00:11:38,920
Go ahead and assign that to Z.

192
00:11:38,930 --> 00:11:46,340
In fact if you just try to do that it's going to say hey type error an SDR object a string object does

193
00:11:46,340 --> 00:11:48,040
not support item assignment.

194
00:11:48,080 --> 00:11:50,540
So that means we see a string like this.

195
00:11:50,540 --> 00:11:53,560
You can no longer mutate it or change it.

196
00:11:53,570 --> 00:11:58,730
So this is known as E mutability the unability to mutate the actual object.

197
00:11:58,730 --> 00:12:02,440
Later on we'll learn about different data types and different data structures that we can mutate that.

198
00:12:02,600 --> 00:12:05,150
But keep in mind strings are immutable.

199
00:12:05,150 --> 00:12:06,960
You can't however concatenate strings.

200
00:12:07,040 --> 00:12:08,090
So that's kind of cool.

201
00:12:08,360 --> 00:12:14,330
So I can say my string plus my string and that's going to concatenate it together so that you'll see

202
00:12:14,330 --> 00:12:18,090
your string once and then it's going to concatenated again off itself.

203
00:12:18,440 --> 00:12:20,690
So then that means you can do something like this.

204
00:12:21,560 --> 00:12:28,100
Hello space concatenated with which is just using the plus sign and then someone's name for example

205
00:12:28,100 --> 00:12:29,940
Hello Jose.

206
00:12:30,140 --> 00:12:34,070
So that's a really quick way to do some print formatting of strings just concatenate them together like

207
00:12:34,070 --> 00:12:34,540
that.

208
00:12:34,610 --> 00:12:35,370
Just keep in mind.

209
00:12:35,420 --> 00:12:40,760
You'll have to be aware spacing because if I just said hello Plus Jose there's technically no space

210
00:12:40,760 --> 00:12:41,510
there.

211
00:12:41,630 --> 00:12:43,510
So when you run that you just see Hello.

212
00:12:43,520 --> 00:12:44,900
Jose is one giant string.

213
00:12:45,110 --> 00:12:46,130
So keep that in mind.

214
00:12:46,190 --> 00:12:48,710
You can concatenate strings in that fashion.

215
00:12:48,710 --> 00:12:50,810
Now I want to talk about some string methods.

216
00:12:50,810 --> 00:12:56,130
So there's lots of methods available on strings so I'm going to change just say capital H.

217
00:12:56,180 --> 00:12:59,030
Hello world.

218
00:12:59,030 --> 00:13:04,480
So if I ever want to capitalize every single letter in the string basically make everything uppercase

219
00:13:05,090 --> 00:13:08,110
I could take my string and then call up or on it.

220
00:13:08,910 --> 00:13:14,010
And if I just call Upper like this with no print C's it's actually going to give a weird response which

221
00:13:14,010 --> 00:13:15,170
will take on just a second.

222
00:13:15,360 --> 00:13:21,300
But in order to uppercase everything you call the variable name dot and then this method upper open

223
00:13:21,300 --> 00:13:22,760
and close princes.

224
00:13:22,770 --> 00:13:27,630
So these are known as methods on an object and we'll talk about methods and a lot more detail when we

225
00:13:27,630 --> 00:13:29,530
discuss object oriented programming.

226
00:13:29,560 --> 00:13:33,540
But right now just kind of keep these things in mind that they are available to you.

227
00:13:33,700 --> 00:13:34,280
So notice now.

228
00:13:34,290 --> 00:13:34,910
Hello world.

229
00:13:34,980 --> 00:13:38,380
Everything's uppercase when I called the upper there now.

230
00:13:38,430 --> 00:13:45,670
Likewise there is a lower so I can say lower save that.

231
00:13:45,900 --> 00:13:47,450
And when I run this back.

232
00:13:47,490 --> 00:13:48,050
Hello world.

233
00:13:48,060 --> 00:13:52,550
Everything's in lowercase now so H and W now become lowercase.

234
00:13:52,560 --> 00:13:59,400
Now if I forget those print C's and I just print out my string the lower what's going to happen is Python's

235
00:13:59,400 --> 00:14:05,460
going to report back hey you have this built in method called lower of the string object at this location

236
00:14:05,550 --> 00:14:08,510
inside your memory to actually execute that method.

237
00:14:08,520 --> 00:14:09,680
Essentially make it run.

238
00:14:09,870 --> 00:14:15,330
You have to have these open and close print C's and that method of open or close print sees versus no

239
00:14:15,360 --> 00:14:16,140
parentheses.

240
00:14:16,290 --> 00:14:20,190
It will make a lot more sense when we actually learn how to create our own functions which is happening

241
00:14:20,220 --> 00:14:21,610
at the end of this section.

242
00:14:21,810 --> 00:14:23,700
OK so those are two methods.

243
00:14:23,700 --> 00:14:25,530
Upper and Lower that are really useful.

244
00:14:25,530 --> 00:14:29,970
Last one I want to mention which is going to kind of be a precursor to our next lecture is the split

245
00:14:29,970 --> 00:14:36,440
method and what happens is the split method will split the string on whitespace to create a list.

246
00:14:36,480 --> 00:14:41,510
We don't technically know what the list is yet so it's kind of when to show you this hello world.

247
00:14:41,520 --> 00:14:47,480
And notice making a list now based off the two strings here separated by the whitespace and then you

248
00:14:47,480 --> 00:14:51,910
can technically expand on that by providing the actual letters you want to split on.

249
00:14:51,950 --> 00:14:59,390
So if you wanted to split every time there was a w such as its capital W I would just say capital W

250
00:14:59,750 --> 00:15:01,290
inside a split.

251
00:15:01,290 --> 00:15:04,220
Run that and then I get to see it split on W..

252
00:15:04,440 --> 00:15:08,690
OK again this is more of a preview than something you need to really learn right now.

253
00:15:08,690 --> 00:15:13,220
Main thing you should be aware of is that you can index and slice from strings and then finally I'm

254
00:15:13,220 --> 00:15:15,260
going to talk about print formatting.

255
00:15:15,260 --> 00:15:17,510
So there's two main ways to do print formatting.

256
00:15:17,510 --> 00:15:21,830
There's actually lots of different ways but the two main ones were going to be using the first one is

257
00:15:21,830 --> 00:15:28,680
let's say we have a user name and we'll just set the sequel to Sammy as the username and then let's

258
00:15:28,680 --> 00:15:33,770
say they have a favorite color so will create a color variable and their favorite color is blue.

259
00:15:34,630 --> 00:15:38,940
Let's imagine I wanted to print something out that said this user names.

260
00:15:38,950 --> 00:15:41,800
Favorite color is blah blah blue.

261
00:15:41,800 --> 00:15:46,270
So that's a little tricky right now because right now I have a user name and color as variables.

262
00:15:46,270 --> 00:15:48,470
What I can't do is say this.

263
00:15:48,770 --> 00:15:57,060
The username save favor it is color.

264
00:15:57,200 --> 00:16:02,600
If I just run this then that's what I'm going to get back to the stream that username favorite is color.

265
00:16:02,600 --> 00:16:08,300
So that's not really helpful because Python doesn't realize I'm asking for the variable username not

266
00:16:08,300 --> 00:16:09,880
the string user name.

267
00:16:09,920 --> 00:16:13,640
So in order to actually make that work I have two options.

268
00:16:13,880 --> 00:16:22,300
One is using the dot format method so I can replace what I want to insert with curly braces so I'll

269
00:16:22,300 --> 00:16:28,470
say the curly braces favorite is curly braces and then right after that double quote I can type that

270
00:16:28,510 --> 00:16:37,400
format and then pasan what I want to be filled in to those curly braces such as username and color.

271
00:16:37,430 --> 00:16:42,110
So what's happening now and you can really see this in the syntax highlighting user name and color here.

272
00:16:42,110 --> 00:16:48,350
Now these are variables in Python using the format method is going to insert them in order to wherever

273
00:16:48,350 --> 00:16:49,720
the curly braces are.

274
00:16:50,090 --> 00:16:51,240
So we'll save that.

275
00:16:51,350 --> 00:16:54,880
Run this and then I get to see the Samie favorite is blue.

276
00:16:54,920 --> 00:17:01,700
So takes the user name Sammy format's it sticks it in there takes the color variable blue formats and

277
00:17:01,700 --> 00:17:02,720
then sticks it in there.

278
00:17:03,590 --> 00:17:08,330
OK the last thing I want to mention is the ability to use f string literals for printing.

279
00:17:08,330 --> 00:17:10,010
And this is something we will see in the course.

280
00:17:10,010 --> 00:17:16,580
However I want to make it very clear this is only available on Python 3.6 and above.

281
00:17:16,580 --> 00:17:22,870
So if you're running Python 3.5 maybe you downloaded Python in early 2018 and 3.6 wasn't available free

282
00:17:22,880 --> 00:17:25,170
yet you may get an error when running this line.

283
00:17:25,190 --> 00:17:29,740
So double check that your version of Python is 3.6 or above.

284
00:17:30,110 --> 00:17:32,450
So this is going to be F string literals.

285
00:17:32,520 --> 00:17:35,060
Is called F string.

286
00:17:36,100 --> 00:17:41,840
Literals and this makes it actually really easy to print format stuff.

287
00:17:41,840 --> 00:17:48,020
So what you do is you type in an F and then a set of either single quotes or double quotes and then

288
00:17:48,020 --> 00:17:51,880
you just pass in your variable names instead of curly braces directly.

289
00:17:52,010 --> 00:17:56,260
So we can say something like the user name

290
00:17:58,900 --> 00:18:03,730
chose color.

291
00:18:03,980 --> 00:18:09,150
So that's going to do is because these are now curly braces and decided to have an F in there.

292
00:18:09,380 --> 00:18:14,400
When I run this I now get back to see the Samie chose blue.

293
00:18:14,600 --> 00:18:21,570
If you forget that f and try running this you're going to get the actual string itself the username

294
00:18:21,590 --> 00:18:22,530
chose color.

295
00:18:22,610 --> 00:18:28,310
So you let Python know hey I'm referring to variables by starting that string with an F outside of the

296
00:18:28,310 --> 00:18:28,850
quotes.

297
00:18:28,850 --> 00:18:34,460
So again it's called F string literals and it's only available in 3.6 and above and you'll be seeing

298
00:18:34,490 --> 00:18:38,750
us using the course because this is essentially the most compact way.

299
00:18:38,810 --> 00:18:41,360
It's more compact than using the dot format method.

300
00:18:41,360 --> 00:18:44,450
But if you don't have 3.6 yet you can always use that format.

301
00:18:44,780 --> 00:18:45,060
OK.

302
00:18:45,080 --> 00:18:46,840
That's really the basics of strings.

303
00:18:46,940 --> 00:18:52,630
We just covered and actually index strings slice strings a few properties of strings and some methods.

304
00:18:52,820 --> 00:18:57,490
And then as well as print formatting if you have any questions feel free to post the Cunio forms.

305
00:18:57,530 --> 00:18:58,520
We'll see at the next lecture.
