Python Compiler
txt = "Learn pythön!" print(txt.encode("ascii", "backslashreplace")) print(txt.encode("ascii", "ignore")) print(txt.encode("ascii", "namereplace")) print(txt.encode("ascii", "replace")) print(txt.encode("ascii", "xmlcharrefreplace")) print(txt.encode("ascii", "strict"))
OUTPUT
b'Learn pyth\\xf6n!'
b'Learn pythn!'
b'Learn pyth\\N{LATIN SMALL LETTER O WITH DIAERESIS}n!'
b'Learn pyth?n!'
b'Learn pythön!'
Traceback (most recent call last):
 File "file_name.py", line 8, in <module>
   print(txt.encode("ascii", "strict"))
UnicodeEncodeError: 'ascii' codec can't encode character '\xf6' in position 10: ordinal not in range(128)
×

Save as Private