Python string strip() method “returns a copy of the string by removing both the leading and the trailing characters (based on the string argument passed).”
Syntax
string.strip([character])
Parameters
character: It is an optional parameter which is the String specifying the characters to be removed. If the character argument is not provided, all leading and trailing whitespaces are removed from the String.
Return value
The string strip() method returns the String copy with both leading and trailing characters stripped.
Example 1: How to Use string strip() Method
data = ' Winter is coming!! '
print(data.strip())
Above code, we have put the space at the start of the String and two spaces at the end.
Output
Example 2: Giving no arguments
If we give no arguments to the strip() method, the leading and trailing whitespaces will be stripped.
str = " database is good! ";
print(str.strip())
Output
database is good!
Example 3: Case sensitive
The string.strip() method is case-sensitive. When we pass a character argument to the method, it will not strip the same character with a different case.
str = "hey, this is bart simpson, the coolest Simpson";
print(str.strip('simpson'))
Output
hey, this is bart simpson, the coolest S
That’s it.

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.
my precious