Monday, November 24, 2025
HomeLanguageshtml.escape() in Python

html.escape() in Python

With the help of html.escape() method, we can convert the html script into a string by replacing special characters with the string with ascii characters by using html.escape() method.

Syntax : html.escape(String)

Return : Return a string of ascii character script from html.

Example #1 :
In this example we can see that by using html.escape() method, we are able to convert the html script to ascii string by using this method.




# import html
import html
  
s = '<html><head></head><body><h1>This is python</h1></body></html>'
# Using html.escape() method
gfg = html.escape(s)
  
print(gfg)


Output :

<html><head></head><body><h1>This is python</h1></body></html>

Example #2 :




# import html
import html
  
s = '<html><head></head><body><h1>GeeksForGeeks</h1></body></html>'
# Using html.escape() method
gfg = html.escape(s)
  
print(gfg)


Output :

<html><head></head><body><h1>GeeksForGeeks</h1></body></html>

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32410 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6785 POSTS0 COMMENTS
Nicole Veronica
11932 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12000 POSTS0 COMMENTS
Shaida Kate Naidoo
6909 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6865 POSTS0 COMMENTS
Umr Jansen
6852 POSTS0 COMMENTS