strip() in python by R4R Team

- strip() is a python in-build function which are used to remove the same content from the string at both end.
- It is combine form of lstrip() and rstrip().
- lstrip() remove left content
- rstrip() remove right content
- so strip() remove the same content at both side of string.

Syntax-

str.strip("str")

Example
string is s="---hello---"
s.strip("-") will give "hello"


program-

s="111111111mytext1111111"
print(s.strip("1"))

s="22222mytext222"
print(s.strip("2"))

s="111111111mytext2222"
print(s.strip("1"))
print(s.strip("2"))
print((s.strip("1")).strip("2"))


output-

mytext
mytext
mytext2222
111111111mytext
mytext


-In this program, we apply strip() function which remove the same content at both side
- But in last string in above program have different content in both the end and we want to remove both content from both the side so that we use (s.strip("1")).strip("2").




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!