What is Unicode error in Python

Python’s string type uses the Unicode Standard for representing characters, which lets Python programs work with all these different possible characters.
In Python, Unicode standards have two types of errors. They are Unicode encode error and Unicode decode error. To include Unicode characters in the Python program we first use Unicode escape symbol \u before any string which can be considered as a Unicode-type variable.
The UnicodeEncodeError normally happens when encoding a unicode string into a certain coding. Since codings map only a limited number of unicode characters to str strings, a non-presented character will cause the coding-specific encode() to fail.
Below shown is an example of UnicodeEncodeError.
>>> u = chr(40960) + 'abcd' + chr(1972) >>> u.encode('utf-8') b'\xea\x80\x80abcd\xde\xb4' >>> u.encode('ascii') Traceback (most recent call last): File "<stdin>", line 1, in <module> UnicodeEncodeError: 'ascii' codec can't encode character '\ua000' in position 0: ordinal not in range(128) >>>
The UnicodeDecodeError normally happens when decoding an str string from a certain coding. Since codings map only a limited number of str strings to unicode characters, an illegal sequence of str characters will cause the coding-specific decode() to fail.
>>> b'\x80abc'.decode("utf-8", "strict") Traceback (most recent call last): File "<stdin>", line 1, in <module> UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte >>>