html.escape()
html.escape() is a Python function in the HTML Module category. Converts special HTML characters (&, <, >, ", ') to HTML-safe entities. The syntax is html.escape(s, quote=True). Parameters: s, quote. Returns: Escaped string. A typical example: import html
html.escape("")
# "<script>alert('xss')</script>". A close sibling is html.unescape(), which converts HTML entities back to characters. A close sibling is html.parser.HTMLParser(), which a push parser for HTML that calls handler methods for tags and data. More about this category: HTML escaping — escape, unescape, HTMLParser. Related HTML Module entries: html.unescape(), html.parser.HTMLParser(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details. You can try html.escape() immediately in the Python playground, look up unfamiliar terms in the glossary, or return to the Python Reference homepage.