Python decode() method
Description
The Python decode() method uses theencodingspecified encoding format to decode the string. The default encoding is the string encoding.
Syntax
The syntax of the decode() method is:
str.decode(encoding='UTF-8',errors='strict')
Parameters
encoding -- The encoding to use, such as "UTF-8".
errors -- Sets the handling scheme for different errors. The default is 'strict', meaning that encoding errors cause a UnicodeError. Other possible values include 'ignore', 'replace', 'xmlcharrefreplace', 'backslashreplace', and any value registered via codecs.register_error().
Return Value
This method returns the decoded string.
Example
The following example demonstrates the decode() method:
Example (Python 3.0+)
#!/usr/bin/python
str = "this is string example....wow!!!";
str = str.encode('base64','strict');
print "Encoded String: " + str;
print "Decoded String: " + str.decode('base64','strict')
The output of the above example is:
Encoded String: dGhpcyBpcyBzdHJpbmcgZXhhbXBsZS4uLi53b3chISE= Decoded String: this is string example....wow!!!
Other Extensions
Python String