Here are some examples showing the differences between the function of "strip()" and "replace()" in Python.
Be careful! strip() will delete any character in the beginning or end of the word that matches "any" character in the word we put in the strip function. For example, we put "& quot;" as a parameter into strip(), then any character matches ('&', 'q', 'u', 'o', 't', ';') will be deleted. It doesn't have to be exactly the same "string."
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#EX.1 | |
>>> x = "citt"" | |
>>> x.strip(""") | |
'ci' | |
>>> x.replace(""","") | |
'citt' | |
#EX.2 | |
>>> x = ""city" is" | |
>>> x.strip(""") | |
'city" is' | |
>>> x.replace(""","") | |
'city is' |