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)
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. p>
Code # 1: Code to decode a string
The encoded string in base64 format is: Z2Vla3Nmb3JnZWVrcw == The decoded string is: pythonengineering
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