我正在尝试检查Python中的字符串是否包含转义字符。最简单的方法是设置一个转义字符列表,然后检查列表中的任何元素是否在该字符串中:
s = "A & B"
escaped_chars = ["&",
""",
"'",
">"]
for char in escaped_chars:
if char in s:
print "escape char '{0}' found in string '{1}'".format(char, s)
有更好的方法吗?
<
等。 - Andrew