decode() is a method specified in Strings in Python 2.
This method is used to convert from one encoding scheme, in which argument string is encoded to the desired encoding scheme. This works opposite to the encode. It accepts 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, e.g ‘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 the string
The encoded string in base64 format is : Z2Vla3Nmb3JnZWVrcw== The decoded string is : geeksforgeeks
Encoding and decoding together can be used in simple application of storing password in back end and many other applications like cryptography which deals with keeping the information confidential.
The small demonstration of the password application is depicted below.
Code #2 : Code to demonstrate application of encode-decode
Password entered : geeksforgeeks Wrong Password!! Password entered : i_lv_coding You are logged in!!
- codecs.decode() in Python
- numpy.defchararray.decode() in Python
- Python | Pandas Series.str.decode()
- Python | Message Encode-Decode using Tkinter
- Python Strings encode() method
- Python 3 Strings | expandtabs() method
- Python | Remove empty strings from list of strings
- Python | Tokenizing strings in list of strings
- C strings conversion to Python
- Python | Interleaving two strings
- Python | Removing strings from tuple
- Python | Extract Strings with only Alphabets
- Python | Union Operation in two Strings
- Python - Selectively Split in Strings
- Python | Extract K sized strings
- Python - Alternate Strings Concatenation
- Python - Strings with Maximum K length
- Python | Identical Strings Grouping
- Python - Combine Strings to Matrix
- Python | C Strings of Doubtful Encoding | Set-1
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.