Hey Everyone,
I am Vikram Salunke
and welcome to another video
in Python for InfoSec
This is video number 6
and 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()
as we can see the
first character of both
the words has been
converted to uppercase
so this is what title() does
so, what do you mean by method?
a method is a action that Python
performs on a piece of a data
the . after name and title()
tells python to make title() method
act on name variable
every method is followed by
a set of parentheses
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
this is a string Python for InfoSec
so as we saw earlier
the string is a collection
of characters
and we can access each
of the character from string
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
str[0]
so we will access the character
at 0th location
we can access the character
from other location also
such as str[7]
we can also slice a string
in this example
let's slice the string
str[5:10]
so, when we used the slicing
this is start position 5
and this is a end position
that is 10
so at 5th position
there is 'n' and at
10th position there is 'r'
so, this is how we do
the slicing
we can also do the slicing
in another way also
such as
str[5:10:2]
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
so, there are so many
methods available for a string
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
so that's it for this video
if you want to solve
exercises and read
the text version
of this video
then please visit
our website vmaskers.com
Thank you :)
Không có nhận xét nào:
Đăng nhận xét