This article describes the Replace method in Python in the form of an instance, which is very useful, as follows:
There are two main types of replace methods:
Last_date = "1/2/3" target is "123"
Method One: Repalce
Date =last_date.replace ('/', ')
Method Two: RE
p = re.compile ("/")
date = P.sub (", last_date)
Note that you must not escape, or the function will not take effect.
The Replace method returns a copy of the string that is replaced with text based on the regular expression, in the following format:
Stringobj.replace (Rgexp, ReplaceText)
Parameters:
Stringobj required Option . The string object or string literal to perform the substitution. The string is not modified by the Replace method.
Rgexp required Option . Is the regular expression object that contains the regular expression pattern or the available flags. It can also be a String object or text. If Rgexp is not a regular expression object, it is converted to a string and the exact lookup is made; do not attempt to convert the string to a regular expression.
ReplaceText required Option . is a string object or string literal, and the position in each matching rgexp in Stringobj is replaced with the text contained in that object. In the Jscript 5.5 or later version, the ReplaceText parameter can also be a function that returns the replacement text.
For example:
Content.replace (' \ n ', '). Replace (' \ R ', '). replace (' \ \ ', ' \\\\ '). Replace (', ', ', ')
It is hoped that the examples mentioned in this paper will play a reference role in Python programming.