All language subtitles for 13. Advanced Strings

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic Download
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
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
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

OK let's talk about advance string so everything we can show you is not going to be used in this course

but I still think it's important to know and there's some important syntax in here to know as well in

just different ways to handle the information that is in front of you.

So let's go ahead and just print out a string or let's make a string first.

Let's do a string of my name and we'll just say my name is heat and similar to before.

If we printed out our name we could say print my name and then if I wanted to print the first initial

of my name or first letter in my name I would just do something like this right.

So this should be familiar.

And if we wanted to print out the last letter we get to say negative one that should be familiar to

you from the list lesson.

So we go ahead and we print this way to say Python 3 and we do our new script again.

You can see that we have big H and a little H because my name ends in both starts and ends in.

So we could also do something like take a sentence and we could say a sentence.

This is a sentence.

And if we wanted to print out the first word of the sentence we would have to know the amount of letters

in it.

So we know here that there is one two three four.

So this would be zero through three.

So let's say if we wanted to print out a sentence here and we knew zero through three.

So remember we don't have to put zero.

We could just put something like this and then if we did 3 3 it would only cut off at the I remember

we have to go one further from our list lesson and we'll be able to print out the word this we can do

the same with sentence.

We can go forward a bunch if we want to or we could do a negative nine because this is nine characters

long through seems like a negative nine through negative one would pull out that whole sentence are

the words sentence I should say so we can manipulate data this way we can also split data so we could

say something like print and do a sentence dot split and this will split based on a delimiter.

Now the delimiter here is by default a space and we cover delimiter as in bash scripting and we're just

going to say hey every time there's a space I want you to split out the sentence let's take a look at

that looks like I made a mistake in my script I didn't spell sentence correctly which cause an error

in the initial script.

So let's try that again.

So you see here it says this.

That's what we're expecting from this one.

And here we have this is a sentence.

It now breaks these out into individual words based on delimiter so let's go a little bit further we

can join a sentence as well.

So let's have a scenario here.

Let's say we want to split a sentence out we'll say sentence split is equal to sentence dot split.

And now we just split up the sentence right and we're putting in this variable of sentence underscore

a split.

Now we could also join a sentence.

So let's make a new variable and we'll call it sentence join.

And here we can just say based on a delimiter I want you to put a space in between everything here.

So every every time you see a word in this sentence split.

So let's go ahead and join any time you see a sentence split here and there's a new word in it.

I want you to go ahead and join those with the space and then we can go ahead and print out a sentence

join and let's see what happens here.

This is a sentence I've brought it all back for us.

So not only can we take away and delimit a sentence by splitting we can also join a sentence and add

our own delimiter in there as well

so one of the most important things that we need to talk about is what happens if we have a quote and

we say something like he said give me all your money.

Well we need to add quotations in here.

But if we do quotations like this well that's just making things are really weird right.

Look at the color of the script.

You can already tell it's going weird.

That's going to throw an error.

But we can use single quotes and double quotes and it'll work.

We could also use single quotes here double quotes inside double quotes on the outside single quotes

on the inside.

And that's a way to have quotes inside of a string.

Let's go ahead and print that out but let's say that you were insistent and you wanted to have double

quotes and then double quotes here.

Well we could do a little bit of character escaping so we could utilize this backslash here and say

hey we're going to keep this string a string and then I'm going to end it right here so this will tell

me that from here to here.

Ignore these characters.

Right.

So we're gonna treat it as a string don't treat it as a quotation and end of string.

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

run it here.

He said give me all your money.

And I realized that I tried to print earlier and probably did Princess Pogues and ever had the print

in there.

I'm sorry for that.

But we could do it either way again we can put the single quotation in here and you'll see the single

quote works but if we were to put in a double quotation it would break it.

So I'm going to control ze a couple of times and this is what the syntax should look like.

This is very very important.

If there's one thing you're going to take away from Van strings please please take this away from it

because you need to know how to do some character escaping and you will encounter that again in your

career.

So a couple more things.

Let's say that we want to have a string here.

Let's just say we'll call the string too much space and we have something like hello.

And we just you know copy data put into this and somehow too much space in here we can strip out the

space so we can just print too much space here and we can do the same thing as we did before and do

something like a strip like this

save it.

And look what happens now.

It's just going to print.

Hello.

There's no space around it.

We're good to go.

So that's a nice little feature.

Another feature that we should know is let's say we had something like print a.

An apple.

What's this going to return

trip.

What it's looking for is does a exists in Apple.

Well what if we did a lower case here.

Try it again and you'll see that it's false.

So it's very case sensitive.

Well what about we wanted to say hey is there an A in the word apple.

And we don't know if it's capitalized not capitalized.

Well we might say something instead like hey we're looking for a letter of a.

And we're looking for the word of Apple.

Right.

But what about we say print letter that lower.

And then we say in word dot lower like this.

Now this becomes improved because we're looking for a specific letter inside of a specific word.

And we lowercase everything we lowercase this letter lowercase all these letters then we're looking

for a specific letter in a word we don't have to worry about case sensitivity.

And you will see this logic come into play when you're thinking about looking for specific items or

specific key phrases or matching anything specifics you might want to consider putting everything in

the lower case and then trying to find it that way unless you are critical on case sensitivity.

So this will probably come up again in your career as you look at code.

So we run that again.

Now you can see that it returns back true.

So one more thing I want to show you and there's a lot of things that we can do with advanced strings

I don't want to beat too much into it because I really feel that this can get into overkill because

there's so many things and tips and tricks that I can show you.

But I really feel like some of this can be out of scope for the course but I do think that as long as

you're taking good notes and it's valuable now you're going to have that as something to remember and

look back upon as you do more Python development.

So one more thing is a format so let's say that your favorite movie is the hangover and we'll just keep

that as a string and let's just say something like print my favorite movie.

Now we have done in the past is and we could just say scenes like this plus you know streaming if it's

not a string or we just say movie right and then we'd have to add a period in here or something along

those lines.

We can improve upon this.

Well you say my favorite movie is.

And then we can just add a little place holder here and then put a period.

Now what we do after this is we just say dot format and then we say movie and now it knows to put in

the movie that we have here for the variable that we have stored in movie and knows to put it into these

brackets here.

We save this and watch what happens.

My favorite movie is the hangover.

So you don't have to do a bunch of spacing and if things get weird you know with with your your string

or you know how to write out your sentence it's very easy to just have these place holders and then

if things change you know it just updates easily.

So this is a very nice way to hold things in a place holder without making these weird formatting changes.

So I like this method as opposed to the concatenation method that I showed you in our first video on

strings.

So if you can take away some things today just take away that you know we have different ways of doing

things we've shown you with the list before of the zero on the negative one I told you isn't it come

up again.

Just know that again zero is the first item or first letter first whatever when we're talking about

Python and we're talking about our variables list strings.

Always start with a zero.

There's different ways to do the same thing and apply them across other items.

Right.

So I've shown you this with lists I've shown you this with strings.

So get those wheels spinning and think about how you can utilize some things.

Now a sentence has all different kinds of methods that we can use with it.

And again we're just touching back on methods and making it a little bit more advanced but we you see

that we can split a sentence.

We can join a sentence.

We can strip a sentence or we can strip a string.

So understanding that there are a lot of cool methods the lower method we could do an upper method.

We've talked about those as well knowing the different types of methods per say like a string or per

class or however you want to combine it together is important as well.

So always do your research when you are looking into you know how can I improve it.

So if you're saying like hey is there a way to make something uppercase just go to Google and say hey

how do I make a string all uppercase.

And of course it's dot upper.

But if you didn't know that then you know the Google machine would know that for you.

And a lot of your code is going to be found on stack exchange or on Google etc..

So just be aware that these things exist and be aware that there are better ways to format your strings.

And there are important syntax when it comes to escaping your quotations as well.

So that's it for this lesson.

We're going to have a couple more little lessons here and then we're going to move into script building

and then we'll be starting our hacking journey.

So I'll catch you over in the next video.

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