﻿1
00:00:00,330 --> 00:00:03,210
‫Now let's move on to strings in Python.

2
00:00:05,090 --> 00:00:14,850
‫So how can we pass a string in a Python, if I just write st python tutorial and execute it

3
00:00:21,370 --> 00:00:28,900
‫I'm getting an error because we need to pass strings in double quotes or single quotes.

4
00:00:30,340 --> 00:00:35,620
‫So we can write in double quotes st python  tutorials.

5
00:00:43,120 --> 00:00:45,400
‫Here we use double quotation marks.

6
00:00:45,580 --> 00:00:48,610
‫You can also use single quotes to pass string.

7
00:00:49,510 --> 00:00:54,070
‫But sometime your string may contain single codes in between.

8
00:00:54,670 --> 00:00:58,810
‫So therefore, it is recommended to use double quotes while passing  strings.

9
00:01:01,610 --> 00:01:04,340
‫Just like numbers we can also assign

10
00:01:04,610 --> 00:01:13,220
‫This string to some variable so we can write str  one, here str one is our variable and we are assigning

11
00:01:13,220 --> 00:01:15,080
‫value st Python tutorial.

12
00:01:25,590 --> 00:01:30,000
‫Now, my str one variable contains this value.

13
00:01:31,800 --> 00:01:40,290
‫Now, if we want to display the value of our str, one variable, I will just write str one and then

14
00:01:40,290 --> 00:01:41,010
‫execute this

15
00:01:41,010 --> 00:01:41,400
‫Command

16
00:01:42,510 --> 00:01:44,580
‫You can see we are getting our output.

17
00:01:45,780 --> 00:01:51,630
‫And you can also notice that st python tutorial is coming in quotation marks.

18
00:01:53,010 --> 00:01:57,440
‫There is also a separate print function in python to print the output.

19
00:01:59,910 --> 00:02:06,850
‫To  print output will write print and in brackets will write str1.

20
00:02:10,670 --> 00:02:13,490
‫You can now notice that there is no quotation marks.

21
00:02:14,660 --> 00:02:19,450
‫And now the values are printed and they are not a part of output.

22
00:02:20,750 --> 00:02:26,480
‫You can see when we just executed str 1, we were getting the content of this variable in

23
00:02:26,480 --> 00:02:27,600
‫the form of output.

24
00:02:27,770 --> 00:02:30,140
‫You can see this out written here.

25
00:02:30,530 --> 00:02:34,010
‫But when we are printing it, python is actually printing it.

26
00:02:34,100 --> 00:02:35,740
‫And this is not a part of out

27
00:02:38,890 --> 00:02:42,530
‫Python even provides formatting options with this print function.

28
00:02:44,160 --> 00:02:48,090
‫So suppose I wanted to use some variable inside my print

29
00:02:48,120 --> 00:02:52,140
‫Command, I can do that by using print formatting.

30
00:02:53,890 --> 00:03:01,750
‫For example, in our previous example, in the phrase st python tutorial, I wanted to pass

31
00:03:01,750 --> 00:03:07,150
‫variable X, which will take python or R depending the value.

32
00:03:12,560 --> 00:03:20,510
‫So if my x is python, I wanted to print st python tutorial, if my x is R, I wanted to print

33
00:03:20,660 --> 00:03:28,340
‫Str tutorial or if X is sql, I wanted to print st sql tutorial.

34
00:03:30,390 --> 00:03:34,320
‫So let's create this variable X and assign it value R

35
00:03:38,200 --> 00:03:43,970
‫Notice that we are using double codes to assign value to this variable.

36
00:03:47,180 --> 00:03:48,590
‫We will first write print

37
00:03:52,240 --> 00:03:59,680
‫And in brackets we will put quotation marks and will pass the array string, which is S-T.

38
00:04:02,040 --> 00:04:10,200
‫And then since I want my second word to be this variable X, I will give curly brackets.

39
00:04:12,130 --> 00:04:15,120
‫And my third word is a constant, which is tutorial

40
00:04:15,520 --> 00:04:17,110
‫So I will write tutorial.

41
00:04:21,590 --> 00:04:25,820
‫Now, I want to tell Python what goes inside this curly bracket.

42
00:04:26,270 --> 00:04:28,910
‫So after this print command, I will put a Dot

43
00:04:31,010 --> 00:04:38,800
‫And write format and in parenthesis, I can write my variable name, which is X.

44
00:04:42,530 --> 00:04:43,340
‫Let's run this.

45
00:04:45,340 --> 00:04:50,800
‫We are getting this error because dot format should be inside the print

46
00:04:50,840 --> 00:04:51,250
‫Command.

47
00:04:51,740 --> 00:04:54,290
‫So we just copy paste it

48
00:05:00,270 --> 00:05:00,380
‫Yes.

49
00:05:01,140 --> 00:05:04,770
‫And now if we execute it, you can see we are getting

50
00:05:05,590 --> 00:05:07,020
‫Str, tutorial.

51
00:05:09,090 --> 00:05:17,070
‫If I change my value of X to SQL and then again run this print command

52
00:05:18,360 --> 00:05:22,350
‫You can see now since our X is SQL.

53
00:05:24,610 --> 00:05:27,760
‫The output is statement is st sql tutorial.

54
00:05:29,410 --> 00:05:33,480
‫So what's happening here is, the curly bracket in print command tells

55
00:05:33,690 --> 00:05:37,960
‫Python to take the value of variable that is mentioned in the dot format

56
00:05:38,230 --> 00:05:39,010
‫Parentheses.

57
00:05:41,340 --> 00:05:44,970
‫If I want, I can also pass two or more than two variables.

58
00:05:45,330 --> 00:05:47,910
‫The syntax will remain the same in that case.

59
00:05:49,200 --> 00:05:55,080
‫And you have to mention the variable names in dot  format in the order you want them to be filled

60
00:05:55,130 --> 00:05:56,030
‫in the curly bracket.

61
00:05:57,700 --> 00:05:59,460
‫So if we just write print.

62
00:06:03,310 --> 00:06:06,190
‫And in bracket will write S.T..

63
00:06:10,620 --> 00:06:13,810
‫Then curly brackets, here our variable X will come.

64
00:06:14,770 --> 00:06:16,810
‫Then after this tutorial

65
00:06:20,140 --> 00:06:21,610
‫and then another curly bracket.

66
00:06:25,940 --> 00:06:36,800
‫And in dot, we can write X and the variable we created earlier, that was var one if we execute this.

67
00:06:38,630 --> 00:06:42,620
‫You can see our var one variable was containing 14.

68
00:06:43,920 --> 00:06:47,970
‫So our printed string is st sql tutorial 14.

69
00:06:49,710 --> 00:06:53,340
‫Now let's discuss some important functions related to strings.

70
00:06:54,570 --> 00:06:55,650
‫The first function.

71
00:06:56,900 --> 00:06:57,830
‫Is length function.

72
00:06:58,250 --> 00:07:01,040
‫It helps us to find the length of our string.

73
00:07:02,980 --> 00:07:06,370
‫The syntax of length function is l e n.

74
00:07:08,150 --> 00:07:16,070
‫Now, if we want to check the length of our str 1 variable we can just mention str one inside parenthesis

75
00:07:16,130 --> 00:07:16,820
‫After length

76
00:07:18,830 --> 00:07:21,830
‫You can see the length of our variable str one.

77
00:07:22,220 --> 00:07:23,330
‫Is 18

78
00:07:25,000 --> 00:07:27,850
‫Also note that is space is also a character.

79
00:07:28,000 --> 00:07:29,770
‫So this length 18.

80
00:07:30,840 --> 00:07:37,150
‫Is count of all the characters, including spaces and other punctuation marks as well.

81
00:07:39,810 --> 00:07:44,010
‫Another string function, which we frequently used, is replace function.

82
00:07:46,380 --> 00:07:53,700
‫You must have used replace function in word or notepad, where you search the word and then replace

83
00:07:53,700 --> 00:07:58,530
‫that word with a new word, replace function in python works

84
00:07:58,710 --> 00:07:59,760
‫Exactly the same.

85
00:08:00,950 --> 00:08:02,390
‫You have to give two words.

86
00:08:04,960 --> 00:08:06,790
‫.First, the word you want to search.

87
00:08:06,970 --> 00:08:09,930
‫And second, the word you want to replace it with.

88
00:08:11,420 --> 00:08:14,730
‫So let's again print our str 1 variable

89
00:08:18,180 --> 00:08:18,740
‫right now.

90
00:08:19,170 --> 00:08:23,060
‫My str one contains st python tutorial.

91
00:08:24,420 --> 00:08:36,180
‫If I want to replace this word python with sql, I will write str one dot replace and in

92
00:08:36,180 --> 00:08:40,200
‫Brackets first the word I want to replace.

93
00:08:41,700 --> 00:08:42,620
‫That is Python.

94
00:08:45,660 --> 00:08:48,750
‫Also remember that Python is case sensitive language.

95
00:08:49,960 --> 00:08:56,110
‫So I have to pass python in lowercase since my variable contained python in lowercase.

96
00:08:56,380 --> 00:08:59,460
‫I want to replace this variable with sql.

97
00:09:00,550 --> 00:09:03,660
‫So after a comma, I will write a sql.

98
00:09:09,870 --> 00:09:12,480
‫You can see that the word by python.

99
00:09:13,710 --> 00:09:16,040
‫Has now been replaced with sql.

100
00:09:17,360 --> 00:09:20,440
‫I can also save this value in another variable.

101
00:09:21,530 --> 00:09:25,100
‫So let's save this value in another variable called x.

102
00:09:30,600 --> 00:09:33,780
‫I will copy paste sole function.

103
00:09:41,110 --> 00:09:42,090
‫If I print x

104
00:09:45,410 --> 00:09:47,990
‫I'll get this, value st sql tutorial.

105
00:09:50,540 --> 00:09:55,190
‫Now let's move on to string indexes and a string slicing.

106
00:09:56,350 --> 00:10:00,220
‫You can see string is a collection of several individual characters.

107
00:10:01,120 --> 00:10:09,060
‫For example, in our variable X, s is a single character, t is a single character.

108
00:10:10,170 --> 00:10:13,920
‫And our whole string is a collection of such characters.

109
00:10:15,620 --> 00:10:19,540
‫These characters are present at a specified position in our string.

110
00:10:20,240 --> 00:10:28,640
‫So, for example, s is present at the first position, t is present at the second position.

111
00:10:29,510 --> 00:10:31,640
‫And similarly, we have a space

112
00:10:31,760 --> 00:10:32,950
‫At the third position.

113
00:10:36,000 --> 00:10:41,910
‫We can extract this individual characters from a variable by specifying their positions.

114
00:10:42,840 --> 00:10:51,390
‫This concept of extracting characters by their position is known as string indexing or string slicing.

115
00:10:53,040 --> 00:10:58,940
‫One thing to note here is that in python, indexing starts with zero.

116
00:11:02,180 --> 00:11:12,080
‫So our character s is present at zero th Index t is present at first index and space is present at

117
00:11:12,890 --> 00:11:13,760
‫two index.

118
00:11:15,810 --> 00:11:21,770
‫So if I want to extract the character which is present at the first index, I will just write our

119
00:11:21,780 --> 00:11:27,960
‫Variable name, which is X and then the square bracket, I will mention the index, which is one.

120
00:11:32,970 --> 00:11:36,870
‫If we execute this, we will get t

121
00:11:36,990 --> 00:11:41,430
‫As our output since t was present at the first Index.

122
00:11:43,190 --> 00:11:46,520
‫Position is different from index, the position of t is two.

123
00:11:46,790 --> 00:11:53,760
‫But since the index starts from zero, our s was present at 0th index and our t was present at

124
00:11:53,790 --> 00:11:54,680
‫First index.

125
00:11:57,540 --> 00:11:59,880
‫I can also mention multiple index.

126
00:12:00,210 --> 00:12:05,850
‫So if I want all  characters which are present from index two to index five.

127
00:12:08,140 --> 00:12:10,570
‫I will write X and in squared bracket

128
00:12:10,840 --> 00:12:11,950
‫I will write two.

129
00:12:14,090 --> 00:12:18,890
‫Then I will provide a colon symbol and then I will write five.

130
00:12:20,030 --> 00:12:25,490
‫This means that I want all characters which are present between index two and five.

131
00:12:27,760 --> 00:12:34,990
‫Notice that our first character is space, our second character is s, and our third character is

132
00:12:35,020 --> 00:12:35,590
‫Q.

133
00:12:37,730 --> 00:12:45,120
‫We are getting all the characters that are present at index two index three, and index four.

134
00:12:46,350 --> 00:12:54,720
‫We are not getting our indexed five variable because the second argument is always excluded while slicing

135
00:12:54,720 --> 00:12:57,090
‫the string using indexes.

136
00:12:58,550 --> 00:13:05,420
‫So two colon five means character present at index two, three and four.

137
00:13:08,840 --> 00:13:17,810
‫Similarly, if we write bracket four Colon six, it will return the characters which are present at

138
00:13:17,810 --> 00:13:19,190
‫index four and five.

139
00:13:21,080 --> 00:13:28,700
‫Index six will be excluded from our selection. indexes, also supports negative argument.

140
00:13:30,110 --> 00:13:33,560
‫Negative stands for counting from the backside of this string.

141
00:13:35,000 --> 00:13:41,630
‫So minus one will be the last character of string, minus two will be the second last character and

142
00:13:41,630 --> 00:13:42,200
‫so on.

143
00:13:44,150 --> 00:13:51,260
‫So if I wanted to print last character of my string, I will write X and in square record I will

144
00:13:51,260 --> 00:13:53,300
‫mention minus one.

145
00:13:58,060 --> 00:14:06,100
‫We are getting l as our output since the last character or our variable X was l

146
00:14:10,150 --> 00:14:14,260
‫While slicing you can also skip the arguments.

147
00:14:14,680 --> 00:14:16,360
‫So if I write X.

148
00:14:18,760 --> 00:14:21,610
‫And in square bracket, I will write colon five.

149
00:14:25,110 --> 00:14:30,750
‫This means that I want all the characters from the start of my string till the index five.

150
00:14:31,440 --> 00:14:32,250
‫If I run this.

151
00:14:36,140 --> 00:14:39,380
‫You can see we are getting all the characters from the start of this string.

152
00:14:40,490 --> 00:14:45,230
‫Similarly, if I want all the characters from Index five.

153
00:14:46,220 --> 00:14:51,440
‫To the end of the string, I will write X and in bracket, I will write five colon.

154
00:14:54,820 --> 00:15:00,020
‫You can see all the characters from the fifth index is present in our output.

155
00:15:03,190 --> 00:15:07,210
‫Now, what if, if I wanted alternate characters from my string.

156
00:15:08,580 --> 00:15:13,410
‫I can do that by mentioning the third parameter, which is the step parameter.

157
00:15:14,520 --> 00:15:17,580
‫So earlier we were passing only two parameters.

158
00:15:17,850 --> 00:15:19,020
‫The starting point.

159
00:15:19,440 --> 00:15:22,350
‫And then after the colon, we were passing the end point.

160
00:15:24,080 --> 00:15:29,510
‫We can also pass the  third argument after another colon symbol as a step argument

161
00:15:31,220 --> 00:15:37,700
‫So if I write X and in squared bracket, I will write two colon ten.

162
00:15:41,280 --> 00:15:49,620
‫This means I want all the characters from index to index nine, remember index 10 is excluded

163
00:15:52,510 --> 00:16:04,420
‫But if I write 2 colon 10 colon 2, this means I want characters with step as two so I will be getting

164
00:16:04,480 --> 00:16:06,630
‫characters present at index 2.

165
00:16:07,570 --> 00:16:11,290
‫And since our step is two it will directly jump to index four.

166
00:16:14,280 --> 00:16:18,000
‫And then to index six and then to index eight.

167
00:16:19,390 --> 00:16:19,920
‫If I run this

168
00:16:22,340 --> 00:16:28,160
‫If I print my x just to compare our output, you can see.

169
00:16:30,200 --> 00:16:35,050
‫Our character at index two was space.

170
00:16:38,590 --> 00:16:41,440
‫Character at Index Four was q.

171
00:16:44,030 --> 00:16:53,120
‫Then character at Index six was again space and then character at Index

172
00:16:53,210 --> 00:16:54,500
‫8 was u.

173
00:16:57,820 --> 00:17:04,140
‫Similarly, if you want to change this step size to three, four or anything, you can do that.

174
00:17:08,010 --> 00:17:13,850
‫One thing you may have noticed is that we are not defining variables while creating the variables.

175
00:17:16,200 --> 00:17:22,950
‫As with other programming languages such as the C, SQL or C++, we don't have to define variable

176
00:17:22,950 --> 00:17:24,030
‫types in Python.

177
00:17:25,600 --> 00:17:30,430
‫Python will automatically assign that type depending on the value present in that variable.

178
00:17:32,520 --> 00:17:40,380
‫So if you are passing variable X as one python will automatically assign X as an integer.

179
00:17:41,130 --> 00:17:48,990
‫If you are passing X as an string, it will automatically assign X as an string or if you are passing

180
00:17:49,440 --> 00:17:50,860
‫it as a decimal point.

181
00:17:52,200 --> 00:17:53,930
‫It will get a floating point type.

182
00:17:55,940 --> 00:18:03,950
‫To know the type of variable we can use type function, we just have to write type and in parenthesis,

183
00:18:04,020 --> 00:18:04,190
‫Write

184
00:18:04,290 --> 00:18:05,050
‫The variable name.

185
00:18:06,090 --> 00:18:10,730
‫here we will write X and we should get a string as our output.

186
00:18:11,730 --> 00:18:12,420
‫You can see.

187
00:18:13,630 --> 00:18:16,510
‫The type of our variable X is str.

188
00:18:17,410 --> 00:18:18,130
‫Similarly.

189
00:18:19,520 --> 00:18:22,820
‫If we get the type of our variable that is.

190
00:18:25,690 --> 00:18:26,560
‫Variable one.

191
00:18:29,310 --> 00:18:29,920
‫We are getting.

192
00:18:30,060 --> 00:18:34,830
‫And since our variable one was containing 14 as a value.

193
00:18:38,810 --> 00:18:46,940
‫Now, if we assign variable 2  a value of five divided by two and we print this variable 2,

194
00:18:46,940 --> 00:18:52,370
‫too, you can see that variable 2, is taking a value 2.5.

195
00:18:53,210 --> 00:18:59,390
‫If we want to get the type of this variable to, we will write type and in bracket will write.

196
00:18:59,390 --> 00:19:06,330
‫Variable 2 we should be getting floating number as decimal is present in our value.

