All language subtitles for 13. Advanced Strings

af Afrikaans
sq Albanian
am Amharic
ar Arabic Download
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,180 --> 00:00:06,410 OK let's talk about advance string so everything we can show you is not going to be used in this course 2 00:00:06,450 --> 00:00:12,110 but I still think it's important to know and there's some important syntax in here to know as well in 3 00:00:12,120 --> 00:00:16,560 just different ways to handle the information that is in front of you. 4 00:00:16,590 --> 00:00:21,540 So let's go ahead and just print out a string or let's make a string first. 5 00:00:21,570 --> 00:00:29,150 Let's do a string of my name and we'll just say my name is heat and similar to before. 6 00:00:29,160 --> 00:00:38,220 If we printed out our name we could say print my name and then if I wanted to print the first initial 7 00:00:38,220 --> 00:00:43,510 of my name or first letter in my name I would just do something like this right. 8 00:00:43,530 --> 00:00:44,940 So this should be familiar. 9 00:00:44,940 --> 00:00:52,410 And if we wanted to print out the last letter we get to say negative one that should be familiar to 10 00:00:52,410 --> 00:00:54,180 you from the list lesson. 11 00:00:54,180 --> 00:01:03,090 So we go ahead and we print this way to say Python 3 and we do our new script again. 12 00:01:03,210 --> 00:01:09,640 You can see that we have big H and a little H because my name ends in both starts and ends in. 13 00:01:09,840 --> 00:01:18,180 So we could also do something like take a sentence and we could say a sentence. 14 00:01:18,180 --> 00:01:20,180 This is a sentence. 15 00:01:21,540 --> 00:01:27,780 And if we wanted to print out the first word of the sentence we would have to know the amount of letters 16 00:01:27,780 --> 00:01:28,480 in it. 17 00:01:28,560 --> 00:01:32,660 So we know here that there is one two three four. 18 00:01:32,880 --> 00:01:35,300 So this would be zero through three. 19 00:01:35,310 --> 00:01:42,480 So let's say if we wanted to print out a sentence here and we knew zero through three. 20 00:01:42,480 --> 00:01:44,580 So remember we don't have to put zero. 21 00:01:44,580 --> 00:01:50,070 We could just put something like this and then if we did 3 3 it would only cut off at the I remember 22 00:01:50,070 --> 00:01:56,760 we have to go one further from our list lesson and we'll be able to print out the word this we can do 23 00:01:56,760 --> 00:01:58,190 the same with sentence. 24 00:01:58,200 --> 00:02:04,680 We can go forward a bunch if we want to or we could do a negative nine because this is nine characters 25 00:02:04,680 --> 00:02:11,850 long through seems like a negative nine through negative one would pull out that whole sentence are 26 00:02:11,850 --> 00:02:20,640 the words sentence I should say so we can manipulate data this way we can also split data so we could 27 00:02:20,640 --> 00:02:29,740 say something like print and do a sentence dot split and this will split based on a delimiter. 28 00:02:29,860 --> 00:02:36,370 Now the delimiter here is by default a space and we cover delimiter as in bash scripting and we're just 29 00:02:36,370 --> 00:02:40,710 going to say hey every time there's a space I want you to split out the sentence let's take a look at 30 00:02:40,720 --> 00:02:47,500 that looks like I made a mistake in my script I didn't spell sentence correctly which cause an error 31 00:02:47,530 --> 00:02:48,640 in the initial script. 32 00:02:48,640 --> 00:02:49,610 So let's try that again. 33 00:02:50,080 --> 00:02:52,690 So you see here it says this. 34 00:02:52,690 --> 00:02:54,640 That's what we're expecting from this one. 35 00:02:54,790 --> 00:02:57,440 And here we have this is a sentence. 36 00:02:57,700 --> 00:03:07,700 It now breaks these out into individual words based on delimiter so let's go a little bit further we 37 00:03:07,700 --> 00:03:10,970 can join a sentence as well. 38 00:03:11,240 --> 00:03:12,620 So let's have a scenario here. 39 00:03:12,650 --> 00:03:21,590 Let's say we want to split a sentence out we'll say sentence split is equal to sentence dot split. 40 00:03:22,530 --> 00:03:27,150 And now we just split up the sentence right and we're putting in this variable of sentence underscore 41 00:03:27,150 --> 00:03:28,530 a split. 42 00:03:28,550 --> 00:03:31,070 Now we could also join a sentence. 43 00:03:31,100 --> 00:03:35,100 So let's make a new variable and we'll call it sentence join. 44 00:03:35,180 --> 00:03:42,260 And here we can just say based on a delimiter I want you to put a space in between everything here. 45 00:03:42,290 --> 00:03:46,240 So every every time you see a word in this sentence split. 46 00:03:46,240 --> 00:03:51,770 So let's go ahead and join any time you see a sentence split here and there's a new word in it. 47 00:03:51,860 --> 00:03:58,940 I want you to go ahead and join those with the space and then we can go ahead and print out a sentence 48 00:03:59,000 --> 00:04:06,260 join and let's see what happens here. 49 00:04:06,280 --> 00:04:09,320 This is a sentence I've brought it all back for us. 50 00:04:09,370 --> 00:04:18,250 So not only can we take away and delimit a sentence by splitting we can also join a sentence and add 51 00:04:18,250 --> 00:04:20,290 our own delimiter in there as well 52 00:04:23,550 --> 00:04:32,520 so one of the most important things that we need to talk about is what happens if we have a quote and 53 00:04:32,580 --> 00:04:39,180 we say something like he said give me all your money. 54 00:04:41,940 --> 00:04:43,970 Well we need to add quotations in here. 55 00:04:43,980 --> 00:04:49,950 But if we do quotations like this well that's just making things are really weird right. 56 00:04:49,950 --> 00:04:51,390 Look at the color of the script. 57 00:04:51,390 --> 00:04:53,020 You can already tell it's going weird. 58 00:04:53,160 --> 00:04:55,230 That's going to throw an error. 59 00:04:55,230 --> 00:05:00,200 But we can use single quotes and double quotes and it'll work. 60 00:05:00,210 --> 00:05:04,980 We could also use single quotes here double quotes inside double quotes on the outside single quotes 61 00:05:04,980 --> 00:05:05,660 on the inside. 62 00:05:06,060 --> 00:05:08,340 And that's a way to have quotes inside of a string. 63 00:05:08,760 --> 00:05:15,320 Let's go ahead and print that out but let's say that you were insistent and you wanted to have double 64 00:05:15,320 --> 00:05:17,880 quotes and then double quotes here. 65 00:05:17,900 --> 00:05:25,550 Well we could do a little bit of character escaping so we could utilize this backslash here and say 66 00:05:25,550 --> 00:05:32,390 hey we're going to keep this string a string and then I'm going to end it right here so this will tell 67 00:05:32,390 --> 00:05:34,990 me that from here to here. 68 00:05:35,420 --> 00:05:38,300 Ignore these characters. 69 00:05:38,300 --> 00:05:38,760 Right. 70 00:05:38,780 --> 00:05:44,620 So we're gonna treat it as a string don't treat it as a quotation and end of string. 71 00:05:44,620 --> 00:05:57,190 So let's run it again and you can see that quote Once we print it we can say print quote and we'll actually 72 00:05:57,190 --> 00:05:58,400 run it here. 73 00:05:58,540 --> 00:06:00,780 He said give me all your money. 74 00:06:00,950 --> 00:06:05,260 And I realized that I tried to print earlier and probably did Princess Pogues and ever had the print 75 00:06:05,260 --> 00:06:05,590 in there. 76 00:06:05,600 --> 00:06:06,720 I'm sorry for that. 77 00:06:07,030 --> 00:06:14,200 But we could do it either way again we can put the single quotation in here and you'll see the single 78 00:06:14,200 --> 00:06:19,200 quote works but if we were to put in a double quotation it would break it. 79 00:06:19,210 --> 00:06:24,290 So I'm going to control ze a couple of times and this is what the syntax should look like. 80 00:06:24,310 --> 00:06:25,600 This is very very important. 81 00:06:25,600 --> 00:06:29,440 If there's one thing you're going to take away from Van strings please please take this away from it 82 00:06:29,980 --> 00:06:34,000 because you need to know how to do some character escaping and you will encounter that again in your 83 00:06:34,000 --> 00:06:35,320 career. 84 00:06:35,320 --> 00:06:36,860 So a couple more things. 85 00:06:37,330 --> 00:06:42,460 Let's say that we want to have a string here. 86 00:06:42,550 --> 00:06:51,620 Let's just say we'll call the string too much space and we have something like hello. 87 00:06:52,080 --> 00:07:00,000 And we just you know copy data put into this and somehow too much space in here we can strip out the 88 00:07:00,000 --> 00:07:09,990 space so we can just print too much space here and we can do the same thing as we did before and do 89 00:07:09,990 --> 00:07:12,090 something like a strip like this 90 00:07:15,660 --> 00:07:16,570 save it. 91 00:07:16,720 --> 00:07:20,070 And look what happens now. 92 00:07:20,070 --> 00:07:20,700 It's just going to print. 93 00:07:20,700 --> 00:07:21,110 Hello. 94 00:07:21,120 --> 00:07:22,320 There's no space around it. 95 00:07:22,320 --> 00:07:23,220 We're good to go. 96 00:07:24,090 --> 00:07:26,280 So that's a nice little feature. 97 00:07:26,280 --> 00:07:32,560 Another feature that we should know is let's say we had something like print a. 98 00:07:32,880 --> 00:07:37,260 An apple. 99 00:07:37,260 --> 00:07:38,280 What's this going to return 100 00:07:41,610 --> 00:07:42,060 trip. 101 00:07:42,760 --> 00:07:46,210 What it's looking for is does a exists in Apple. 102 00:07:46,210 --> 00:07:49,240 Well what if we did a lower case here. 103 00:07:49,330 --> 00:07:51,670 Try it again and you'll see that it's false. 104 00:07:51,670 --> 00:07:53,080 So it's very case sensitive. 105 00:07:53,860 --> 00:07:59,380 Well what about we wanted to say hey is there an A in the word apple. 106 00:07:59,530 --> 00:08:03,320 And we don't know if it's capitalized not capitalized. 107 00:08:03,370 --> 00:08:08,060 Well we might say something instead like hey we're looking for a letter of a. 108 00:08:08,320 --> 00:08:12,270 And we're looking for the word of Apple. 109 00:08:12,880 --> 00:08:13,360 Right. 110 00:08:14,080 --> 00:08:20,390 But what about we say print letter that lower. 111 00:08:21,490 --> 00:08:27,970 And then we say in word dot lower like this. 112 00:08:27,970 --> 00:08:33,400 Now this becomes improved because we're looking for a specific letter inside of a specific word. 113 00:08:33,580 --> 00:08:39,370 And we lowercase everything we lowercase this letter lowercase all these letters then we're looking 114 00:08:39,370 --> 00:08:43,190 for a specific letter in a word we don't have to worry about case sensitivity. 115 00:08:43,330 --> 00:08:49,750 And you will see this logic come into play when you're thinking about looking for specific items or 116 00:08:49,760 --> 00:08:55,750 specific key phrases or matching anything specifics you might want to consider putting everything in 117 00:08:55,750 --> 00:09:00,580 the lower case and then trying to find it that way unless you are critical on case sensitivity. 118 00:09:00,580 --> 00:09:05,580 So this will probably come up again in your career as you look at code. 119 00:09:05,710 --> 00:09:06,760 So we run that again. 120 00:09:06,760 --> 00:09:09,640 Now you can see that it returns back true. 121 00:09:10,270 --> 00:09:14,800 So one more thing I want to show you and there's a lot of things that we can do with advanced strings 122 00:09:14,800 --> 00:09:21,790 I don't want to beat too much into it because I really feel that this can get into overkill because 123 00:09:21,790 --> 00:09:24,300 there's so many things and tips and tricks that I can show you. 124 00:09:24,340 --> 00:09:29,890 But I really feel like some of this can be out of scope for the course but I do think that as long as 125 00:09:29,890 --> 00:09:35,350 you're taking good notes and it's valuable now you're going to have that as something to remember and 126 00:09:35,620 --> 00:09:39,160 look back upon as you do more Python development. 127 00:09:39,160 --> 00:09:47,440 So one more thing is a format so let's say that your favorite movie is the hangover and we'll just keep 128 00:09:47,440 --> 00:09:55,900 that as a string and let's just say something like print my favorite movie. 129 00:09:55,960 --> 00:10:05,650 Now we have done in the past is and we could just say scenes like this plus you know streaming if it's 130 00:10:05,650 --> 00:10:12,740 not a string or we just say movie right and then we'd have to add a period in here or something along 131 00:10:12,740 --> 00:10:13,540 those lines. 132 00:10:13,760 --> 00:10:15,550 We can improve upon this. 133 00:10:15,560 --> 00:10:17,980 Well you say my favorite movie is. 134 00:10:18,290 --> 00:10:22,990 And then we can just add a little place holder here and then put a period. 135 00:10:23,100 --> 00:10:32,740 Now what we do after this is we just say dot format and then we say movie and now it knows to put in 136 00:10:32,860 --> 00:10:39,590 the movie that we have here for the variable that we have stored in movie and knows to put it into these 137 00:10:39,590 --> 00:10:40,980 brackets here. 138 00:10:41,210 --> 00:10:45,590 We save this and watch what happens. 139 00:10:45,880 --> 00:10:47,630 My favorite movie is the hangover. 140 00:10:47,740 --> 00:10:53,980 So you don't have to do a bunch of spacing and if things get weird you know with with your your string 141 00:10:53,980 --> 00:10:59,200 or you know how to write out your sentence it's very easy to just have these place holders and then 142 00:10:59,200 --> 00:11:02,350 if things change you know it just updates easily. 143 00:11:02,350 --> 00:11:08,450 So this is a very nice way to hold things in a place holder without making these weird formatting changes. 144 00:11:08,560 --> 00:11:14,860 So I like this method as opposed to the concatenation method that I showed you in our first video on 145 00:11:14,860 --> 00:11:15,490 strings. 146 00:11:15,850 --> 00:11:23,380 So if you can take away some things today just take away that you know we have different ways of doing 147 00:11:23,380 --> 00:11:27,310 things we've shown you with the list before of the zero on the negative one I told you isn't it come 148 00:11:27,310 --> 00:11:28,210 up again. 149 00:11:28,210 --> 00:11:34,990 Just know that again zero is the first item or first letter first whatever when we're talking about 150 00:11:35,650 --> 00:11:39,400 Python and we're talking about our variables list strings. 151 00:11:39,400 --> 00:11:40,930 Always start with a zero. 152 00:11:40,930 --> 00:11:45,330 There's different ways to do the same thing and apply them across other items. 153 00:11:45,340 --> 00:11:45,640 Right. 154 00:11:45,640 --> 00:11:49,060 So I've shown you this with lists I've shown you this with strings. 155 00:11:49,060 --> 00:11:52,890 So get those wheels spinning and think about how you can utilize some things. 156 00:11:52,930 --> 00:11:57,680 Now a sentence has all different kinds of methods that we can use with it. 157 00:11:57,730 --> 00:12:02,920 And again we're just touching back on methods and making it a little bit more advanced but we you see 158 00:12:02,920 --> 00:12:04,660 that we can split a sentence. 159 00:12:04,660 --> 00:12:06,940 We can join a sentence. 160 00:12:06,940 --> 00:12:10,720 We can strip a sentence or we can strip a string. 161 00:12:10,780 --> 00:12:17,890 So understanding that there are a lot of cool methods the lower method we could do an upper method. 162 00:12:17,890 --> 00:12:24,310 We've talked about those as well knowing the different types of methods per say like a string or per 163 00:12:24,310 --> 00:12:28,690 class or however you want to combine it together is important as well. 164 00:12:28,690 --> 00:12:34,010 So always do your research when you are looking into you know how can I improve it. 165 00:12:34,420 --> 00:12:39,730 So if you're saying like hey is there a way to make something uppercase just go to Google and say hey 166 00:12:39,730 --> 00:12:41,960 how do I make a string all uppercase. 167 00:12:41,980 --> 00:12:43,360 And of course it's dot upper. 168 00:12:43,370 --> 00:12:47,260 But if you didn't know that then you know the Google machine would know that for you. 169 00:12:47,410 --> 00:12:52,240 And a lot of your code is going to be found on stack exchange or on Google etc.. 170 00:12:52,270 --> 00:13:00,670 So just be aware that these things exist and be aware that there are better ways to format your strings. 171 00:13:00,730 --> 00:13:06,740 And there are important syntax when it comes to escaping your quotations as well. 172 00:13:06,820 --> 00:13:09,720 So that's it for this lesson. 173 00:13:09,730 --> 00:13:14,230 We're going to have a couple more little lessons here and then we're going to move into script building 174 00:13:14,230 --> 00:13:17,080 and then we'll be starting our hacking journey. 175 00:13:17,230 --> 00:13:19,000 So I'll catch you over in the next video. 17848

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.