repalce a string with python
I have tried the replace function but it gives me an str error
CodePudding user response:
a="test1,test2"
a="\"" a.replace(",","\",\"") "\""
print(a)
CodePudding user response:
So this is the answer to what you asked.
old_string = "test1,test2"
new_string = old_string.replace(',', '","')
# new_string = 'test1","test2'
When you want to use "
in a string, you can use the single quote for the string.
However are you sure you are not looking for the split
functionality.