Answer the question
In order to leave comments, you need to log in
Python replace related question?
I need to write some code to change the text [b] and [/b] into <.b> and <./b> directly.
I used the replace function, but only one pair of these tags can be changed there.
That is, I wrote like this:
stroka = input()
new_stroka = stroka.replace("[b]", "<.b>", '[/b]', '<./b>')
print(new_stroka) , but this is a mistake.
stroka = input()
new_stroka = stroka.replace("[b]", "<.b>")
new_stroka = stroka.replace("[/b]", "<./b>")
print(new_stroka) , but in this case, only the second line changes, it ignores the first one,
Who knows how this can be implemented, help.
Answer the question
In order to leave comments, you need to log in
stroka = '[b]ew f f sd fa sd fasdfasdf[/b]'
stroka.replace("[b]", "<.b>").replace("[/b]", "<./b>")
'<.b>ew f f sd fa sd fasdfasdf<./b>'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question