Tim*_*ler 0 python string replace list
我正在使用Pycharm作为在python中编码的软件工具.
这些单词是文本格式,但它们应该返回不同的输出
word = "<p>Santa is fat</p>"
secondword = "Potato & Tomato"
thirdword = "Koala eats http://koala.org/ a lot</p>"
Run Code Online (Sandbox Code Playgroud)
我想将以下每个"<",">","&"替换 为 " <
"," >
"," &
"
所以输出应该是这样的
outputword = "<p>Santa is fat</p>"
outputsecondword = "Fish & Chips"
outputthirdword = ""<p>Koala eats <a href='http://koala.org/'>http://koala.org/</a> a lot</p>"
Run Code Online (Sandbox Code Playgroud)
请注意,第三个单词是URL.我不想使用html库.我是Python的菜鸟,请为我提供简单的解决方案.我考虑使用列表,但每当我替换列表中的字符时,它都不会改变
小智 8
Python附带电池:
import html
word = "<p>Santa is fat</p>"
print(html.escape(word))
Run Code Online (Sandbox Code Playgroud)
输出:
<p>Santa is fat</p>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
341 次 |
最近记录: |