Important Notice:

Course Content
The Calendar Module
Library Function/Predefined Functions
0/4
Sys Module
Library Function/Predefined Functions
0/2
OS Module
Library Function/Predefined Functions
0/2
Functions in Python (Chapter-10) M3-R5
About Lesson

encode():-

        The encode() method encodes the string, using the specified encoding. If no encoding is specified, UTF-8 will be used.

Syntax:-       string.encode(encoding=encoding, errors=errors)

txt = “My name is Ståle”

x = txt.encode()

print(x)

Output

b’My name is Stxc3xa5le’

txt = “My name is Ståle”

print(txt.encode(encoding=”ascii”,errors=”backslashreplace”))

print(txt.encode(encoding=”ascii”,errors=”ignore”))

print(txt.encode(encoding=”ascii”,errors=”namereplace”))

print(txt.encode(encoding=”ascii”,errors=”replace”))

print(txt.encode(encoding=”ascii”,errors=”xmlcharrefreplace”))

Output:-

b’My name is St\xe5le’

b’My name is Stle’

b’My name is St\N{LATIN SMALL LETTER A WITH RING ABOVE}le’

b’My name is St?le’

b’My name is Ståle’

error: Content is protected !!