How to encode and decode a string and list in python.
pls any one can explain with examples.
#here is a string example : word = 'Sriram' x = word.encode('UTF-16', 'ignore') print (x) #this method takes 2 parameters : the first one being the encoding scheme to be used : I used 'UTF-16', in the above example. #the second parameter is the error handling scheme: it could be : 'strict', ' ignore ' or 'replace': I used 'ignore' in the above example. # if you don't include the parameters, the method will still work, but using default character encoding and error handling schemes. #the default for errors is 'strict'. __________________________________ Now, to decode and print the above string: print (x.decode('UTF-16', 'ignore')) #again, the explanation is similar to that of the encoding method : #feel free to play around with the various character encoding/decoding and error handling schemes available, and find out what works for you : All the best!
I only used x to print out your name, but, you can print out any string directly, if that's how you prefer: also, try to write a code, based on the example above, and see for yourself, what encode and decode can do: you'll understand the concept better, that way: and you're welcome! ( ͡o ͜ʖ ͡o)
thanks for your info.. May I know what is the use of encode and decide ? here x also printing Sriram...
can you precise your question please ?