Hey Everyone,I am Vikram Salunke and welcome to Python for InfoSec.
This is part 6 and in this post we will see String Methods.

In this video we are going to see String Methods.

As we saw earlier, the string is nothing but collection of characters and in Python there are multiple methods available to manipulate the string.

Let's create a new string

name = "vikram salunke"

Now let's use method title()

print name.title()

string methods

As we can see the first character of both the words has been converted to uppercase. So this is what title() does

What do you mean by method?

a methods is a action that python performs on a piece of a data

the . (dot) after name and title() tells python to make title() method act on name variable.

Every method is followed by a set of panrentheses because methods often need additional information to do their work. That information is provided inside the parentheses

title() method doesn't need any additional information so the parentheses are empty

title() displays each word in title case, where each word begins with a capital letter

Now let's look at the string

string methods

So as we saw earlier the string is a collection of characters.

string methods

And we can access each of the character.

string methods

Remember this thing, the position always start with 0 so if you want to access the first element we have to access that string's 0th character and so on.

Using str[0] we can access the character at 0th location. As well as we can access the character from other location also such as str[7]

string methods

we can also slice a string.

In this example let's slice the string.

str[5:10]

string slicing

So, when we used the slicing, start position 5 and end position is 10. So at 5th position there is 'n' and at 10th position there is 'r'

We can also do the slicing in another way also such as

str[5:10:2]

string slicing

This has start position, end position and steps. So, it will take the 2 steps.

We can also use a lower method

str.lower()

and convert this string into the lower case

As well as we can convert this string into upper case also

str.upper()

We can also find a particular word in the string. So let's find 'vik'

str.find("vik")

If that word is not present in the string then it will return -1

Let's try to find another string

str.find("Python for InfoSec")

So, as we know Python is available in string and it is at 0th position

To find a length of a string we use

len(str)

So, 18 is a length of string

So, there are many methods available for string which we will look when we will need them.

If you want to join our in person class then please click here we are doing trainings in some upcoming InfoSec conferences.
And if you have any doubts, any questions then you can tweet me @vikramsalunke20
We are uploading daily new videos on YouTube click here to subscribe.
If you want to solve the exercises on this topic those are below. Solve the exercises and check your understandings. Thank you :)