+ 2

How to encode and decode a string and list in python.

pls any one can explain with examples.

9th May 2017, 5:14 PM
Sriram Chowdary Mellamputi
Sriram Chowdary Mellamputi - avatar
4 Respuestas
+ 57
#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!
9th May 2017, 5:51 PM
<^>washika D<^>
<^>washika D<^> - avatar
+ 49
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)
10th May 2017, 11:48 AM
<^>washika D<^>
<^>washika D<^> - avatar
+ 2
thanks for your info.. May I know what is the use of encode and decide ? here x also printing Sriram...
10th May 2017, 9:49 AM
Sriram Chowdary Mellamputi
Sriram Chowdary Mellamputi - avatar
+ 1
can you precise your question please ?
9th May 2017, 5:36 PM
Hbeo
Hbeo - avatar