[no audio]
Friends, here we are going to
discuss some more operations on your strings,
but the result of this operations is Boolean data.
That means the result you will get like either true or false,
right? Let me take the operations of your strings which
will give the result as a Boolean data.
So before that guys let me open my Python Shell.
I mean first the command line, then type 'python', and you will
enter into Python terminal, right. There define any string.
Let's say, my_str=
[no audio]
"Hello", anything.
[no audio]
Then simply 'print(dir(my_str))'.
[no audio]
You have here different
operations, right. Already
we know how to get these operations, and already we have seen
some of the operations like 'upper', 'title', 'swapcase', right,
and then 'lower', 'capitalize', something 'casefold' we have seen.
Now, I want to go with some other operations such that
the result should be either true or false, or whatever the
operations we are going to discuss now that operation's results
is like true or false, or simply Boolean data.
Let's take very simple operation first, 'endswith', right. Guys,
let me open my editor.
So I am going to write a Python script name for that, right.
So let me take Python script name as
[no audio]
'boolean_result_
[no audio]
string_operations'. So guys these operations are very, very helpful
in your real time.
Let's say I am taking 'my_str=', suppose simply "Python".
Okay. Now what I am doing is I am checking,
[no audio]
'my_str'
"."
[no audio]
'startswith("p")'. Is it starting with "p"? In that case you
will use this operation. See the output. 'False'.
The reason is you are starting with capital "P",
but you're checking with small "p".
Now, is it starting with small capital "P"? Yes, 'True'.
[no audio]
Right. So you will take this type of operations in your conditional
statements. So you will come to know there how to use this.
Before that you just try to observe the output. The same way
I can check not only with single letter guys,
I can also check with word also, no problem.
'my_str.startswith', let's say "Python". No problem.
Just check it. Yes, it's 'True'.
Right. The same way
you can also check like 'print(my_str.endswith)',
[no audio]
is it ending with "n"? You can take either single letter, or let's
say I am taking "hon", no problem.
I mean group of characters also you can check it.
The only thing is if the given string is ending with "hon" then
you will get output as 'True'.
That's it.
[no audio]
So this is starting and ending, right. Then
let me open your commands,
I mean your terminal, and see that. Let me take something called
[no audio]
let's say 'islower'.
You have likewise, you know so many operations.
Let me take 'islower'.
'print(my_str.islower)'.
I mean is it in lower case letters?
No, because first letter is capital, remaining all are small
that's why you'll get output as 'False'. See the output.
[no audio]
Then, guys 'islower',
'isupper', this type of operations are important in your
real-time. 'isupper'
[no audio]
this is also 'False' because your letter, your string's, your string
characters are not, all characters of your string are not in
uppercase, only first letter,
that's why you're getting 'isupper' as 'False'.
Let me take 'my_str.istitle'.
Yes, you will get 'True'. You know 'title' is nothing but if
you have suppose some multiple words in a given string
the first letter of your each and every word should be a
capital. That format is there no, that's why you are getting 'True'.
Suppose if I add something like "Python tutorials", now you'll
get 'False' because in the second word "t" is small.
Let me take it as a capital and check it now.
Yes, now it's 'True'.
Right. So 'title' is done. Likewise
let me take some, 'isspace'.
So is there any space in the given string?
Is there any space in the given string? So for that you can
use this operation,
'isspace'. Yes, we have a space
no, that's why you're going to get output as,
sorry, 'isspace'
You're having, along with your space you're having letters as well, right?
Let me take one more example here, only space. The thing is
'my_new_str' is only space, right. Now check on your new string
'isspace'. Is it a space?
Yes, 'True'.
But if you observe on your given string, 'my_str' it is the
combination of spaces and some alphabets.
That's why it is giving result on this 'False', right?
That's fine. Now, let me go with one more thing.
[no audio]
'isalpha'.
Right. 'isalpha'.
Nothing but, is your string consists of only alphabets?
'my_new_str', let me take 'my_str' not 'my_new_str'.
Let me take our string.
So what is our string? First
let me print it. This one, right?
Is it alpha?
Yes, 'True' no?
[no audio]
Why are we getting 'False'? You have space. Space is not the
alphabet, right?
Let me remove that space.
Now, see the output. You're getting 'True'.
[no audio]
Right. So space is not alphabet,
that's why 'isalpha' giving 'False'.
If you remove that space it will give a 'True'.
That's fine.
Now, let me go with the one more thing called 'isnumeric' for
your numbers, right?
'isprintable', right, you can print. 'istitle', isupper'.
Let me take one more thing called 'is', yeah, I will take this
one, 'isnumeric'.
[no audio]
See that I am checking,
'print(my_str.isnumeric)'.
What is the output? You are getting output as
'my_new_str', sorry. That is commented
no. Let me take 'my_str'.
See the error is, "my_new_str" is not defined, because we
commented that. That's why Python is unable to identify that
variable. Anyway, it's fine. Now see the output. What you
are getting? 'False'. 'isnumeric',
see our string is not numeric
no, our string consists of alphabets.
Let's redefine your string.
equals to something which consists of only numbers, a string
which consists of numbers. Now see the output. You are getting
'True' because your string consists of only numbers. 'isnumeric'.
Right. So guys this type of operations are very, very important.
Right.
So you have some operations, like you can check by going through
document. This 'isalnum', 'isalpha',
'isascii', 'isdecimal', right,
'isdigit', 'isidentifier', 'islower', 'isnumeric',
'isprintable', 'isspace'.
Nothing is there. Simply 'help(str)' you will get all the operations,
its meaning, right?
You just go down, by entering 'capitalize'
there is a meaning, right. 'casefold', right.
So likewise you have all operations here. Just go with only
'is' something, like that, which gives the result as Boolean
data, 'True' or 'False'.
So this guys, this type of operations are very, very important
in your real-time.
You just try to practice with your remaining operations
which are there like this, right, 'isalpha', 'is' you know,
'isascii', 'isdecimal', something like that, right. In next video
we'll see some more operations on your strings, okay?
Okay guys, thank you for watching this video.
[no audio]