Python String decode() method
Python String decode() method
The string.decode() method decodes the string using the codec registered for encoding. Default encoding is the current default string encoding. It may raise errors to set a different error handling scheme.
Syntax
decode([encoding[, errors]])
Parameter
Encoding: This parameter represents a String specifying the encoding to use. The default value is UTF-8
Errors: This parameter is given to set a different error handling scheme. The default for errors is 'strict', meaning that encoding errors raise a UnicodeError.
Return
This method returns the decoded string.
Example 1
# Python String program explaining # the decode() method # initializing the string Str = "This is my Python String example"; # encoding the specified string Str = Str.encode('base64','strict'); # printing the encoded string print ("Encoded String: " + Str) # decoding the encoded string print "Decoded String: " + Str.decode('base64','strict')
Output
Encoded String: VGhpcyBpcyBteSBQeXRob24gU3RyaW5nIGV4YW1wbGU= Decoded String: This is my Python String example
Example 2
# Python String program explaining # the decode() method # initializing the string txt = "My name is Reema" # decoding the string x = txt.decode() # printing the decoded string print(x)
Output
My name is Reema