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’s a smart way for users to do it. Now we will start introducing you to using the strip() function in Python. Hope you understand.
str = ",,,,,,....cat...,,," x = str.strip(",.") print(x)
The strip() function prints out the string identical to the original and removes the characters specified in the argument.
characters: the character you want to delete
Example 1: delete space characters
str = " cat " x = str.strip() print(x)
# Don't use strip() str1 = "Linux for people" print(str1) # Use strip() str2 = "for people" print(str1.strip(str2))
Linux for people
We introduced you to using the strip() function in Python.
Thank you for reading!
Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications including CCNA RS, SCP, and ACE. As an IT engineer and technical author, he writes for various websites.