Related Ads Link

Strip, Istrip and Rstrip - Python String Methods

Strip, Lstrip and Rstrip – Python String Methods

Strip, Istrip and Rs trip – Python String Methods: Hey Guys, Welcome to CodingLio, Here you will learn Programming with Professionals. We have already created a Community for This. By the way, let’s move forward to the Topics of today which is Python String Models. Today we will talk about three python string models i.e Strip python , Lstrip and Rstrip. Here we started.

What is Python Strings?

Python strings are the popular type in python, we create them by just enclosing the Characters in Quotes. One more thing, you must know is python treats single quotes same as double quotes. there is no difference between them. The working is same too. Creating string in python is not as rocket science, It’s really easy by defining values to any variable. Today we are gonna talk about three types of String one by one, Here is the first one;

Strip Python String Method:

Strip in python usually just provides you the copy of string after removing the Chars from the End as well as the beginning. Look at this simple example to understand:

#!/usr/bin/python

str = “000000I just love CodingLio000000”;
print str.strip( ‘0’ )

And here is the output of the following:

I just love CodingLio

So here you can see, The Char “0” is Stripped from the beginning and from the End. Lest heads forward to the next python string.

Lstrip Python String Method:

Lstrip has the very similar working as strip(). All istrip do is, It removes The Chars from the Beginning only. not from the Ending. Carefully Look at the Example:

#!/usr/bin/python

str = “000000I just love CodingLio000000”;
print str.lstrip( ‘0’ )

And here is the output of the following:

I just love CodingLio000000

So easy.! No? now talk about the last one which is;

Rstrip Python String Method:

Rstrip is really similar to the Lstrip among the python string models. All Rstrip does is, It removes the CHars from the Endanding of the string. here is the same example to show its working:

#!/usr/bin/python

str = “000000I just love CodingLio000000”;
print str.rstrip( ‘0’ )

And here is the output of the following:

000000I just love CodingLio

I think you understand the working of these all string methods in python

Conclusion:

I tried to Clarify these strip in python, Lstrip and Rstrip with their examples. Hope you find this post helpful. my achievement is only when you find something helpful here. Keep visiting Cheers.!!



A Programmer by Passion and a Passionate Blogger by Heart <3 . CodingLio was my Dream Idea, I wanted To Create a Medium where, Geeks can actually Learn Something.


Leave a Reply

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

%d bloggers like this: