|

Strings | Python tutorial in Sinhala Learn Basic of Python Programming #8 Video

Watch the video before reading this.

Let`s talk about Strings under python.

As usual we have opened Pycharm. Today we are talking about Strings. We have talked about strings in previous videos. When you type strings, You remember that what we type is typed inside the upper comma.

For an example,

t = "pasiya"
print (type(t))

answer,

Class 'str'

Process finished with exit code 0

If we type t = “pasiya” and then type print(type (t)) and run this coding, You can see that the output is class ‘str’. str means String. We can use even two commas instead of an upper comma.

Example,

a = "apple"
print(a)

answer,

apple

Process finished with exit code 0

Let me take an example as a = “apple”. Here we have simply equated the string “apple” with the variable “a”. I have also made a video about variables. You can watch the video. Then we need to print this string. “apple”. I will type print  ( a ) and run it. You can see the output. “apple” We typed was printed in the same way.

And also if we need a paragraph We can type like this,

b = '''Your paragraph here'''

Let’s see the range.

p ="programmimg"
print(b[2]) 

answer

o

Process finished with exit code 0

Here I need to output the character “o”. So then print(b[2] ) The output is given as 0.

Now let’s talk how to type the characters of Strings. For that I’ll take For Loop.

for s in "pasiya":

print(s)

I type for s in “pasiya”: and I print that variable. Then you can see the output is printed as line by line.

p
a
s
i
y
a

Process finished with exit code 0

Next we will see the length of a string.

d = "Hello, World"
print(len(d))

answer,

12

Process finished with exit code 0

I take ” d ” as a variable. Then I type d = ” Hello,  World “. And then I print(len(d)). The output is given as 12. Why did 12 come here as the output? Because there were 12 characters to build this string. And also python can identify commas and spaces.

Finally let’s learn about the check string

What happens if we check any of words we are typing as a string. Here it simply happens like this.

abc = "man is in the house"

print("in" in abc)

answer,

True

Process finished with exit code 0

I take “abc” as a variable. Then I type “man is in the house”. I have to check if there’s a word “in”. So I type like this print( “in” in abc). Then I run this coding. You can see the output is true. “in” word is in that string.

Here is also the same thing. I have to check “house”. So I print( “house ” in abc). I run this coding. The output is shown as True. Because there’s that word in the string.

Now let’s see what we can do by typing a word that is not in this string.

abc = "man is in the house"

print("kite" not in abc)

answer,

True

Process finished with exit code 0

I print( “kite” not in abc ). And then I run this coding. You can see the output is true.

I’ll tell you how to use If condition for this,

if "man" is in abc:

print (Yes, 'man' is in here)

answer,

Yes, 'man' is in here

Process finished with exit code 0

I take if “man” is in abc. Then I print ( Yes, ‘man’, is in here ). I run the coding. So the output is ” Yes man is in here “.

Another example is ,

if "kite" not in abc:

print (No,'kite' is here)

answer,

No,'kite' is here

Process finished with exit code 0

I take if “kite” not in abc. Then print( No, ‘kite’ is here ). The output is “No, ‘kite’ is here”. Because “kite” is not in abc.

So that`s all We talked about in this video I hope you will learn anything from this video.

Subscribe My Channel for watch More Educational Contents.

Thank You.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *