1
00:00:00,009 --> 00:00:05,510
Welcome back. Now, let's spend a bit more time to talk about strings.

2
00:00:05,880 --> 00:00:09,850
So far, we've worked with the hello world string.

3
00:00:09,859 --> 00:00:13,210
And I did say that whenever you're wrapping your text,

4
00:00:13,850 --> 00:00:17,389
you typically want to use double quotation marks. However,

5
00:00:17,809 --> 00:00:21,670
that's not always true.

6
00:00:21,739 --> 00:00:25,579
The default is to wrap your text with double quotation marks. However,

7
00:00:25,920 --> 00:00:29,829
you can actually get away by using single quotation marks.

8
00:00:29,840 --> 00:00:31,870
So let me just go over here right now and

9
00:00:32,200 --> 00:00:32,970
edit that.

10
00:00:33,290 --> 00:00:36,069
I'm using single quotation marks. I press run

11
00:00:36,220 --> 00:00:38,869
and you can see it works perfectly fine.

12
00:00:39,200 --> 00:00:43,590
So you don't always have to use double quotation marks.

13
00:00:44,240 --> 00:00:49,090
The natural question you might have here is OK. So when do we use single?

14
00:00:49,099 --> 00:00:51,299
When do we use double? Does it really matter?

15
00:00:52,310 --> 00:00:55,709
In most cases, it really comes down to your personal preference,

16
00:00:55,819 --> 00:00:59,740
whether you are a single quotation user or a double quotation user,

17
00:00:59,750 --> 00:01:02,630
the default most programmers tend to go with the double

18
00:01:02,830 --> 00:01:03,909
quotations

19
00:01:04,599 --> 00:01:09,139
and there are instances where you could actually even use both of them

20
00:01:09,269 --> 00:01:10,970
in the same string

21
00:01:11,589 --> 00:01:12,970
as an example.

22
00:01:13,300 --> 00:01:16,110
What if I wanted to say

23
00:01:16,569 --> 00:01:18,809
something like he said

24
00:01:18,949 --> 00:01:19,690
hello?

25
00:01:20,559 --> 00:01:21,139
Right.

26
00:01:21,470 --> 00:01:23,220
So let me just go over here right now

27
00:01:24,510 --> 00:01:25,279
and say,

28
00:01:25,489 --> 00:01:26,309
he

29
00:01:26,610 --> 00:01:27,489
said

30
00:01:30,510 --> 00:01:30,910
and

31
00:01:31,760 --> 00:01:33,339
going to say hello,

32
00:01:34,059 --> 00:01:39,680
how would we be able to print this out successfully?

33
00:01:39,690 --> 00:01:41,599
Because if we click run right now,

34
00:01:41,819 --> 00:01:43,319
it's gonna give us an error message.

35
00:01:43,330 --> 00:01:47,699
Ok, we need to wrap these texts, these letters in quotation marks.

36
00:01:48,040 --> 00:01:49,489
But how do we go about it?

37
00:01:49,959 --> 00:01:51,819
Well, we could do this.

38
00:01:52,239 --> 00:01:53,580
I could go over here right now.

39
00:01:53,940 --> 00:01:55,839
Add a single

40
00:01:56,120 --> 00:01:57,580
quotation mark. Oops, sorry,

41
00:01:58,290 --> 00:01:59,550
it has to be inside.

42
00:02:00,230 --> 00:02:02,730
So the single quotation mark first.

43
00:02:03,040 --> 00:02:03,550
OK.

44
00:02:03,949 --> 00:02:07,569
And now for the actual words that he said hello,

45
00:02:07,739 --> 00:02:10,220
I'm going to use the double quotation marks in

46
00:02:10,229 --> 00:02:12,770
here to wrap the exact word hello itself.

47
00:02:13,399 --> 00:02:14,169
And then

48
00:02:14,380 --> 00:02:18,979
whenever actually this is pretty common in programming languages. OK?

49
00:02:19,199 --> 00:02:22,300
Whenever you have like an opening quotation mark,

50
00:02:22,509 --> 00:02:28,050
you want to have a closing quotation mark as well. So I'm gonna add

51
00:02:28,320 --> 00:02:30,460
the single quotation mark right there.

52
00:02:30,899 --> 00:02:32,539
And now if I click run,

53
00:02:32,820 --> 00:02:36,160
you can see right now it actually works.

54
00:02:36,479 --> 00:02:38,529
We could do the exact opposite.

55
00:02:38,750 --> 00:02:42,250
I could start off with a double quotation mark. OK?

56
00:02:42,509 --> 00:02:46,339
And then I'm gonna come over here right now, wrap hello

57
00:02:46,899 --> 00:02:48,699
in the single quotation marks and then

58
00:02:48,839 --> 00:02:50,419
add the closing

59
00:02:50,589 --> 00:02:56,100
double quotation marks run and you can see it works perfectly fine.

60
00:02:57,100 --> 00:02:57,820
However,

61
00:02:59,029 --> 00:03:05,279
what if I wanted very long strings, right? So I do have my Epsom

62
00:03:05,679 --> 00:03:08,000
generator in here. So let me just grab

63
00:03:08,360 --> 00:03:10,759
this first paragraph over here. OK.

64
00:03:11,509 --> 00:03:12,979
Copy, come over here.

65
00:03:13,649 --> 00:03:14,470
Now,

66
00:03:14,949 --> 00:03:16,610
I could actually

67
00:03:16,990 --> 00:03:19,729
wrap everything as big as it is

68
00:03:19,970 --> 00:03:22,899
inside of the double quotation, mac click run

69
00:03:23,199 --> 00:03:24,750
and it's gonna work perfectly fine.

70
00:03:25,479 --> 00:03:27,149
But what if

71
00:03:27,589 --> 00:03:31,100
I actually wanted to create some space? And so, for example,

72
00:03:31,399 --> 00:03:33,589
I wanted to have some space in here.

73
00:03:33,759 --> 00:03:36,639
I come over here right now and add some space in

74
00:03:36,889 --> 00:03:39,410
right now. It's all kind of disorganized.

75
00:03:39,750 --> 00:03:40,779
I click run.

76
00:03:41,050 --> 00:03:44,110
And now we're gonna have an arrow message.

77
00:03:44,119 --> 00:03:48,910
It's not working anymore because Python cannot understand

78
00:03:48,919 --> 00:03:52,419
the space in between the lines of text.

79
00:03:53,110 --> 00:03:53,940
So

80
00:03:54,270 --> 00:03:55,820
this is where

81
00:03:56,160 --> 00:04:01,470
the triple quotation marks will come in. So watch this. OK.

82
00:04:01,580 --> 00:04:03,660
I'm gonna add 123.

83
00:04:04,309 --> 00:04:07,440
Okay. Oops, sorry about that.

84
00:04:08,690 --> 00:04:09,990
That is three. OK?

85
00:04:10,350 --> 00:04:12,149
And of course, I'm gonna come over here right now

86
00:04:12,509 --> 00:04:13,550
and add

87
00:04:14,350 --> 00:04:17,809
the close in three quotation marks. And now if I click run

88
00:04:18,220 --> 00:04:19,170
and there you go,

89
00:04:20,160 --> 00:04:22,440
you can see it actually works. So

90
00:04:22,670 --> 00:04:26,679
there are certain instances where you may want to use triple quotation marks if

91
00:04:27,380 --> 00:04:29,519
you have very specific kind of spacing.

92
00:04:29,850 --> 00:04:35,190
Uh It's also typically used for like uh documentation, lighting lines of code,

93
00:04:35,200 --> 00:04:35,880
things like that.

94
00:04:35,890 --> 00:04:38,440
That's where you would use the triple quotation marks.

95
00:04:38,450 --> 00:04:42,320
Now, we could also combine strings,

96
00:04:42,589 --> 00:04:42,940
all right.

97
00:04:42,950 --> 00:04:48,160
So as an example, let me quickly show you, let me create a new variable here and say X

98
00:04:48,480 --> 00:04:49,040
OK

99
00:04:49,690 --> 00:04:54,000
equals and then in double quotation marks, I'm going to say hello.

100
00:04:54,720 --> 00:04:55,309
OK?

101
00:04:55,420 --> 00:04:59,010
And then I could create a second variable Y

102
00:04:59,950 --> 00:05:00,730
equals

103
00:05:01,529 --> 00:05:02,589
world.

104
00:05:04,010 --> 00:05:04,510
OK?

105
00:05:05,260 --> 00:05:05,859
And now

106
00:05:06,529 --> 00:05:08,619
if I wanted to combine both of them,

107
00:05:09,299 --> 00:05:11,179
I could say print

108
00:05:11,850 --> 00:05:14,730
parenthesis very simply

109
00:05:14,980 --> 00:05:16,959
X plus

110
00:05:17,279 --> 00:05:17,950
Y.

111
00:05:19,519 --> 00:05:21,100
And now if I click run,

112
00:05:21,359 --> 00:05:23,260
there you go. Hello world.

113
00:05:23,369 --> 00:05:27,790
But if we wanted to add the space between hello and world, all I can do

114
00:05:27,950 --> 00:05:32,890
is I can either add the space at hello right here.

115
00:05:32,899 --> 00:05:37,179
So I've added the space after the o click on run, You have hello world or

116
00:05:37,519 --> 00:05:38,730
I could do the opposite

117
00:05:39,100 --> 00:05:42,980
and simply add the space at the beginning of W click on run

118
00:05:43,109 --> 00:05:47,220
and there you go, you have the exact same result. Now let's

119
00:05:47,450 --> 00:05:50,500
make this just a little bit more sophisticated, this program,

120
00:05:50,510 --> 00:05:51,940
just a little bit more sophisticated.

121
00:05:52,119 --> 00:05:55,029
I'm going to introduce to you a new function

122
00:05:55,269 --> 00:05:59,160
called input. So so far we've been working with print.

123
00:05:59,329 --> 00:06:04,959
Now let me introduce to you input. So input is basically a function that will ask

124
00:06:05,230 --> 00:06:08,279
the user to provide something. OK? So

125
00:06:08,600 --> 00:06:15,290
I'm going to say input and then in parenthesis, I'm going to say say something,

126
00:06:15,299 --> 00:06:16,739
please.

127
00:06:17,250 --> 00:06:17,779
OK.

128
00:06:18,440 --> 00:06:20,660
So if I run,

129
00:06:20,880 --> 00:06:24,029
oh, sorry about that. If I run the command,

130
00:06:24,209 --> 00:06:27,309
you can see right now you say say something, please. And now if I say

131
00:06:27,529 --> 00:06:32,119
hi, my name is Alex and I press enter,

132
00:06:32,410 --> 00:06:33,730
nothing happens.

133
00:06:34,019 --> 00:06:35,570
OK? Because

134
00:06:35,779 --> 00:06:40,100
our program, all it does is to ask the user to say something

135
00:06:40,440 --> 00:06:45,140
and that's it. It's not going to do anything with what the user has actually said

136
00:06:45,540 --> 00:06:50,649
so to make this a little bit more advanced, I'm gonna go back

137
00:06:50,820 --> 00:06:51,570
in here.

138
00:06:51,720 --> 00:06:53,119
Let's remove this

139
00:06:53,619 --> 00:06:57,059
and let's create a new variable. I will say user

140
00:06:57,390 --> 00:06:58,640
response.

141
00:06:59,179 --> 00:07:02,339
OK? This is going to be the name of my variable. And by the way,

142
00:07:02,709 --> 00:07:04,720
let me just say something real quick.

143
00:07:05,500 --> 00:07:06,559
It's good etiquette,

144
00:07:06,570 --> 00:07:10,510
good programming etiquette whenever you're creating names for your variables

145
00:07:10,519 --> 00:07:13,679
or your functions and you're combining two words together.

146
00:07:13,690 --> 00:07:16,399
In this case right now, I'm combining user and response.

147
00:07:16,970 --> 00:07:17,869
The

148
00:07:18,209 --> 00:07:22,980
second word, the first letter typically should be in capital letters.

149
00:07:23,209 --> 00:07:28,890
That's why the R for response here is in capital. I'm just saying, OK, so just

150
00:07:29,029 --> 00:07:30,440
bear that in mind. So

151
00:07:31,049 --> 00:07:32,959
here the response equals

152
00:07:33,600 --> 00:07:34,209
OK?

153
00:07:34,500 --> 00:07:36,459
And I'm gonna say input

154
00:07:36,980 --> 00:07:37,880
and now

155
00:07:38,049 --> 00:07:39,899
in brackets, I'm gonna say,

156
00:07:40,459 --> 00:07:43,299
say something,

157
00:07:44,519 --> 00:07:45,739
please.

158
00:07:46,630 --> 00:07:47,200
OK?

159
00:07:48,010 --> 00:07:48,929
However,

160
00:07:49,119 --> 00:07:50,679
I'm going to come down here,

161
00:07:51,839 --> 00:07:52,899
I'm going to now

162
00:07:53,260 --> 00:07:54,220
use

163
00:07:54,480 --> 00:07:56,059
the print

164
00:07:56,170 --> 00:07:57,140
function

165
00:07:58,359 --> 00:07:59,269
in brackets,

166
00:07:59,420 --> 00:08:02,029
gonna say user response.

167
00:08:02,799 --> 00:08:03,390
That's it

168
00:08:03,769 --> 00:08:04,779
pretty straightforward.

169
00:08:05,220 --> 00:08:07,799
I'm gonna go ahead right now. Run the command.

170
00:08:08,250 --> 00:08:10,589
It says say something, please. So I'm gonna say

171
00:08:10,950 --> 00:08:16,109
my name is Alex Press enter and there you go.

172
00:08:16,250 --> 00:08:20,000
Now, it's saying my name is Alex.

173
00:08:20,220 --> 00:08:24,440
So successfully introduce to you a new function which is input,

174
00:08:24,450 --> 00:08:26,459
which will ask the user to provide something.

175
00:08:26,910 --> 00:08:28,500
We've talked about how

176
00:08:29,170 --> 00:08:30,649
to use the single quotation marks,

177
00:08:30,660 --> 00:08:33,479
the double quotation marks as well as the triple quotation marks.

178
00:08:33,710 --> 00:08:37,280
And I've also shown you how we can actually combine strings

179
00:08:37,409 --> 00:08:42,119
by creating multiple variables and simply using the plus operator

180
00:08:42,299 --> 00:08:43,710
to combine them.

181
00:08:43,719 --> 00:08:44,799
So gradually,

182
00:08:44,809 --> 00:08:49,020
gradually we're getting better and better at walking with Python and string.

183
00:08:49,030 --> 00:08:49,330
So

184
00:08:49,440 --> 00:08:53,229
thank you for watching the video. And of course, I will see you in the next class.

