Python string replace not working
As I am trying to replace some characters in python string but it is not working.
I am using this code:
name = abc000
name.replace(“000”,””)
It showed proper output in the python interpreter. Then I tried it in Pycharm by adding the following line
print(name)
but still not working. What to do if python replace not working.
You are getting this replacement issue because you are using the replace method incorrectly.
You can do it using the below code:
name="abc000"
modified_name=name.replace(“000”,””)
print(modified_name)
Note: When you call the replace method on a string in python you get a new string with the contents replaced as specified in the method call. You are not storing the modified string but are just using the unmodified string.