strip() is a built-in Python function used to strip the string of the characters specified in the argument and print out the string without the specified characters.
It's a useful tool to quickly remove unwanted characters from a string or text.
Here at LinuxAPT, we shall look into how to use the strip() function in Python.
More about the Strip() Function
The strip() function prints out the string identical to the original and removes the characters specified in the argument.
Strip() Function syntax is given below:
- characters: the character you want to delete
Examples of using the Strip() Function
1. Take a look at the below function:
str = ",,,,,,....cat...,,,"
x = str.strip(",.")
The Output will look like this:
2. Delete space characters:
str = " cat "
x = str.strip()
The output will give:
3. Another one is given here:
# Don't use strip()
str1 = "Linux for people"
# Use strip()
str2 = "for people"
The Output will give:
Linux for people
[Need help in fixing Python function issues? We can help you. ]