Latest web development tutorials

Python decode () method

Python strings Python strings


description

Python decode () method to specify the encoding format decoding coded strings. The default encoding is a string encoding.

grammar

decode () method syntax:

str.decode(encoding='UTF-8',errors='strict')

parameter

  • encoding - To use the code, such as "UTF-8".
  • errors - set a different error handling scheme. The default is 'strict', meaning a coding error caused UnicodeError. Other values ​​may have to have 'ignore', 'replace', 'xmlcharrefreplace' 'backslashreplace' and no value registered by codecs.register_error ().

return value

This method returns a string decoded.

Examples

The following example shows decode () instance method:

#!/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')

Examples of the above output results are as follows:

Encoded String: dGhpcyBpcyBzdHJpbmcgZXhhbXBsZS4uLi53b3chISE=

Decoded String: this is string example....wow!!!

Python strings Python strings