Python String decode() Method
The decode() method decodes bytes objects in the specified encoding format. The default encoding is ‘utf-8’.
Python String decode() Syntax
Syntax of the decode() method.
bytes.decode(encoding="utf-8", errors="strict")
Python String decode() Parameters
- encoding — The encoding to use, such as "UTF-8".
- errors — Set different error handling schemes. The default is ‘strict’, meaning that an encoding error causes a UnicodeError. Other possible values are ‘ignore’, ‘replace’, ‘xmlcharrefreplace’, ‘backslashreplace’ and any value registered with codecs.register_error(). for any value.
Python String decode() Return Value
This method returns the decoded string.
Python String decode() Example#1
The following example shows an instance of the decode() method.
#!/usr/bin/python3
str = "apidemos.com"
# encoding string
str_enc = str.encode("UTF-8")
# printing the encoded string
print ("The encoded string in base64 format is : ", str_enc)
# printing the original decoded string
print ("The decoded string is : ",)
print (str_enc.decode('utf8', 'strict'))
Output: