how to replace maltipal char from string and substitute new char
breamoreboy at gmail.com
breamoreboy at gmail.com
Thu Oct 12 07:04:56 EDT 2017
On Thursday, October 12, 2017 at 10:46:03 AM UTC+1, Iranna Mathapati wrote:
> Hi Team,
>>> How to replace multipal char from string and substitute with new char with
> one line code
>> Ex:
>> str = "9.0(3)X7(2) " ===========> 9.0.3.X7.2
>> need to replace occurrence of '(',')' with dot(.) chars
>> output:
>> 9.0.3.X7.2
>>> Thanks,
>>> help(str.replace)
replace(...)
S.replace(old, new[, count]) -> str
Return a copy of S with all occurrences of substring
old replaced by new. If the optional argument count is
given, only the first count occurrences are replaced.
Hence:-
>>> '9.0(3)X7(2)'.replace('(','.').replace(')', '.')
'9.0.3.X7.2.'
--
Kindest regards.
Mark Lawrence.
More information about the Python-list
mailing list