python string replace() method when replacing a character with surrounding spaces only replaces the first occurrence -
I have a string that I am trying to change when it is located around the place below the character:
<> & gt; & Gt; & Gt; Strvar = "a a b b" gt; & Gt; & Gt; Strvar.replace ('a', 'r') "rrbb" #Works! & Gt; & Gt; & Gt; Strvar.replace ('a', 'r') "rrbb" #Works! & Gt; & Gt; & Gt; Strvar.replace ('a', 'r') "rrbb" #Works! & Gt; & Gt; & Gt; Strvar.replace ('a', 'r') "r a bb" # Only the first event has been changed & gt; & Gt; & Gt; Strvar.replace ('b', 'r') "aarb" # Only the first event is replaced
My question is why in the last two circumstances why not replace the workplace Can not be found
Your problem is that you have only one example of a string that can be changed.
Li one
a
Only one in The only set is (starting from the left), so only a replacement.
Comments
Post a Comment