-
-
Save IndhumathyChelliah/62a1e32e483f3bdf41e22d05dcd86263 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s1= "example öf strings" | |
print (s1) #Output:example öf strings | |
#Use backslash for the character that can't be encoded | |
print(s1.encode(encoding="ascii",errors="backslashreplace")) #Output:b'example \\xf6f strings' | |
#ignores the character that can't be encoded | |
print(s1.encode(encoding="ascii",errors="ignore"))#Output:b'example f strings' | |
#replace the character that can't be encoded with the text explanining the character. | |
print(s1.encode(encoding="ascii",errors="namereplace"))#Output:b'example \\N{LATIN SMALL LETTER O WITH DIAERESIS}f strings' | |
#Replace the character that can't be encoded with the question mark | |
print(s1.encode(encoding="ascii",errors="replace"))#Output:b'example ?f strings' | |
#Replace the character that can't be encoded with xml character. | |
print(s1.encode(encoding="ascii",errors="xmlcharrefreplace"))#Output:b'example öf strings' | |
#strict-Raise Unicode Error | |
print(s1.encode(encoding="ascii",errors="strict")) | |
#Output:UnicodeEncodeError: 'ascii' codec can't encode character '\xf6' in position 8: ordinal not in range(128) | |
#errors are not mentioned.Default is strict-Raise Unicode Error. | |
print(s1.encode(encoding="ascii")) | |
#Output:UnicodeEncodeError: 'ascii' codec can't encode character '\xf6' in position 8: ordinal not in range(128) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment