<分区>
我正在尝试实现一个替换以下值的函数:
# > with >
# < with <
# " with "
# & with &
我的函数总是出错。到底哪里出了问题?
def escape_html(s):
data = list(s)
if ">" in data:
data.replace(">",">")
if "<" in data:
data.replace("<","<")
if '"' in data:
data.replace('"',""")
if "&" in data:
data.replace("&","&")
word = data.join()
return word
print escape_html("<>")
注意:这更像是一个基本的编程问题。我的重点是我的功能不起作用的原因。我不能为这个项目使用外部库。