This tutorial explains the Python
decode() method with arguments and examples. Before we dive into the Python
decode() method, let’s first build some background knowledge about encoding and decoding so you can better understand its purpose. 👇
Encoding and Decoding – What Does It Mean?
Programs must handle various characters in several languages. Application developers often internationalize programs to display messages and error outputs in various languages, be it English, Russian, Japanese, French, or Hebrew.
Python’s string type uses the Unicode Standard to represent characters, which lets Python programs work with all possible characters.
Unicode aims to list every character used by human languages and gives each character its unique code. The Unicode Consortium specifications regularly update its specifications for new languages and symbols.
A character is the smallest component of the text. For example, ’a, ‘B’, ‘c’, ‘È’ and ‘Í’ are different characters. Characters vary depending on language or context. For example, the character for “Roman Numeral One” is ‘Ⅰ’, separate from the uppercase letter ‘I’. Though they look the same, these are two different characters that have different meanings.
The Unicode standard describes how code points represent characters. A code point value is an integer from 0 to 0x10FFFF. 
What are Encodings?
A sequence of code points forms a Unicode String represented in memory as a set of code units. These code units are mapped to 8-bit bytes. Character Encoding is the set of rules to translate a Unicode string to a byte sequence.
UTF-8 is the most commonly used encoding, and Python defaults to it. UTF stands for “Unicode Transformation Format”, and the ‘8’ refers to 8-bit values used in the encoding. 
Encoders and decoders convert text between different representations, and specifically, the Python
decode() function converts bytes to string objects.
decode() method converts/decodes from one encoding scheme for the argument string to the desired encoding scheme. It is the opposite of the Python
decode() accepts the encoding of the encoded string, decodes it, and returns the original string.
Here’s the syntax of the method:
decode(encoding, error) str.decode([encoding[, errors]]) # Example: str.decode(encoding='UTF-8',errors='strict'
|Specifies the encoding to decode. Standard Encodings has a list of all encodings.|
|Decides how to handle the errors:|
Other possible values are:
text = "Python Decode converts text string from one encoding scheme to the desired one." encoded_text = text.encode('ubtf8', 'strict') print("Encoded String: ", encoded_text) print("Decoded String: ", encoded_text.decode('utf8', 'strict'))
- Encoded String:
b'Python Decode converts text from one encoding scheme to desired encoding scheme.'
- Decoded String:
Python Decode converts text from one encoding scheme to desired encoding scheme.
>>> b'\x81abc'.decode("utf-8", "strict") Traceback (most recent call last): File "<pyshell#55>", line 1, in <module> b'\x81abc'.decode("utf-8", "strict") UnicodeDecodeError: 'utf-8' codec can't decode byte 0x81 in position 0: invalid start byte >>> b'\x80abc'.decode("utf-8", "backslashreplace") '\\x80abc' >>> b'\x80abc'.decode("utf-8", "ignore") 'abc'