Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
community creator

What is the strip() method for strings in Python?

G.Sri Ram Charan

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Python comes with a lot of built-in functions. One of the important functions is strip().

For strings in Python, the strip() method is used to return the copy of the string in which all the characters have been stripped from the beginning and the ending of the string.

Syntax:

str_name.strip([characters])

If the character’s argument is not provided, all leading and trailing white spaces are removed from the string.

When a string’s character on the left or right doesn’t match with the rest of characters in the argument, it stops removing the leading characters.

Code

s=" hihi ice hihi "
print(s.strip())
#All the white space in left and right are removed
print(s.strip(" hie"))
#All the whitespace,h,i,e in the left and right string are removed
print(s.strip("rom"))
#No characters were removed
null

RELATED TAGS

python
community creator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring