We'll come to an overview of our Python business today.
We will talk about how to work and manipulate strings in Python.
Let's start with making a string lower or uppercase in Python.
We have a lowercase string now, let's capitalize it using the upper function.
Now it's reverted back to a whole lower case using the lower function
cool.
Now let's take a look at the split function since it's very important in Python.
The split function will split in a string.
You happen to illest by default.
It will split your string using space as a delivery.
Let's see how it works.
I'm going to create a variable that holds the string.
Hello World.
Notice there is a space between hello and world and that's how our split function will split our string
into one list with two elements.
Let's check the time of our variable now,
as you noticed, is change from string to a list.
Now we can only access the first element using number zero.
Let's see how we use this with function to split usernames and from passwords in an output that we have
now, we split this output with this function into two parts.
We will use the first part with zero and then we split it again.
But this time we will use Colen as a delimiter.
Now we get this, we get the second element, which is number one, and that should give us our username.
We can all we can do all of that again, but in the same line, let's try that.
Nice.
Let's do it again and save it in a different variable called user.
Now, let's do the same with the password, but keep in mind, the password part is the second element.
If we split it so it will be element number one, not zero.
Looks like it didn't like our key.
Let's try it with a password.
Nice.
Now let's take a look at the replace function when we create our own PIN testing tools.
We sometimes need to read a file and replace or insert a word in that file.
Let's see an example.
And create a variable of the string python.
Now let's replace the word python with Ruby.
We sometimes have a new line in our string, but we can see it first, let's see how how we identify
a new line, our strength, and then how do we remove it?
Let's print our variable, my.
If you notice here, we have a new line.
But normally sometimes you don't see that.
But if we print our string using the R e park or represent function, we can see everything in it.
Now we can see the new line, it's a backslash, and at the end, let's remove this new line at the
end of our string using the strip function.
Nice.
We can also remove it using the replace function and replace the new language that empty quotes.
Let's try that.
It is gone.
We get the same result, but the strip function only removes new line at the end of the string.
So if we now changed a new line to be in the middle of our string, it won't work.
And that's when we use the replace function and instead we have reached the end of this lesson.
Thank you.
And see you in the next one.