Python decode() method
Description
The Python decode() method decodes a string using encoding the specified encoding. The default encoding is the string encoding.
Syntax
Syntax of the decode() method:
str.decode(encoding='UTF-8',errors='strict')
Parameters
-
encoding -- the encoding to use, such as "UTF-8".
-
errors -- sets different error handling schemes. Defaults to 'strict', meaning an encoding error raises a UnicodeError. Other possible values are 'ignore', 'replace', 'xmlcharrefreplace', 'backslashreplace', and any value registered through 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
'
)
;
"
Encoded String:
"
str
;
"
Decoded String:
"
str
.
decode
(
'
base64
'
,
'
strict
'
)
The output of the above example is:
Encoded String: dGhpcyBpcyBzdHJpbmcgZXhhbXBsZS4uLi53b3chISE=
Decoded String: this is string example....wow!!!
Python Strings