decode () — this is the method specified in Strings in Python 2.
This method is used to convert from a single encoding scheme where the argument string is encoded to the desired encoding scheme. This works the opposite of encoding. It takes the encoding of the encoding string to decode it and returns the original string.
Syntax: decode (encoding, error)
Parameters:
encoding: Specifies the encoding on the basis of which decoding has to be performed.
error: Decides how to handle the errors if they occur, eg ’strict’ raises Unicode error in case of exception and ’ignore’ ignores the errors occurred.Returns: Returns the original string from the encoded string.
Code # 1: Code to decode a string
|
Output:
The encoded string in base64 format is: Z2Vla3Nmb3JnZWVrcw == The decoded string is: pythonengineering
Application:
Joint encoding and decoding can be used in a simple backend password storage application and in many other applications such as cryptography, which is concerned with keeping information confidential.
A short demonstration of the use of a password is shown below.
Code # 2: Code to demonstrate the use of encoding and decoding
|
Output: