0

I want to write a python function to search a line, looking for a symbol, and if it is finds, then replace it by a value. The goal is to solve a cgi problem So, the line looks like:

<h1><font color="#CC6600">%<br></font></h1>

and I wanted to check if % is on the page and then replace it is by a word, let's say, Suffle. How could I accomplish that?

1 Answer 1

5

use str.replace():

In [24]: strs="""<h1><font color="#CC6600">%<br></font></h1>"""

In [25]: strs.replace("%","Suffle")
Out[25]: '<h1><font color="#CC6600">Suffle<br></font></h1>'

To check the presence of a substring in a string we use in:

In [26]: "%" in strs
Out[26]: True
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.