replaced by given string.
given_string = "I think %s is a perfectly normal thing to do in public." def sub1(s): return given_string % s
given_string2 = "I think %s and %s are perfectly normal things to do in public." def sub2(s1, s2): return given_string2 % (s1, s2)
string substitution
given_string2 = "I'm %(nickname)s. My real name is %(name)s, but my friends call me %(nickname)s." def sub_m(name, nickname): return given_string2 % {"nickname": nickname, "name" : name} print sub_m("Mike", "Goose")
replacement
def escape_html(s): for (i, o) in (("&", "&"), (">", ">"), ("<", "<"), ('"', ""e;")): s = s.replace(i, o) return s print escape_html('>')
import cgi def escape_html(s): return cgi.escape(s, quote = True) print escape_html('"hello, & = &"')