Decode UTF-8 in Python | Delft Stack

文章推薦指數: 80 %
投票人數:10人

To decode a string encoded in UTF-8 format, we can use the decode() method specified on strings. This method accepts two arguments, encoding and ... PythonHow-To'sCheckOperatingSystemUsingPythonConditionalAssignmentOperatorinPythonPlayMp3FileUsingPythonRemoveCommasFromStringinPythonConvertBytestoIntinPython2.7and3.xConvertInttoBytesinPython2andPython3GetandIncreasetheMaximumRecursionDepthinPythonCreateandActivateaPythonVirtualEnvironmentreportthisad reportthisadHowToPythonHow-To'sDecodeUTF-8inPythonEncodingreferstoencodingastringusinganencodingschemesuchasUTF-8.Decodingreferstoconvertinganencodedstringfromoneencodingtoanotherencodingscheme.Inthisarticle,wewilllearnhowtodecodeastringencodedinUTF-8formatinPython.DecodingUTF-8StringsinPythonTodecodeastringencodedinUTF-8format,wecanusethedecode()methodspecifiedonstrings.Thismethodacceptstwoarguments,encodinganderror.encodingacceptstheencodingofthestringtobedecoded,anderrordecideshowtohandleerrorsthatariseduringdecoding.Theerrorargumentacceptsonlytwovalues:strictandignore.strictraisesaUnicodeerrorwhensomeerroroccurs,andignoreignoretheerrors.Thedecode()methodreturnstheoriginalstring.RefertothefollowingPythoncodetounderstandhowtousethedecode()method.s="HelloWorld" encoded=s.encode("UTF-8") decoded=encoded.decode("UTF-8") print("EncodedString:",encoded) print("DecodedString:",decoded) Output:EncodedString:b'HelloWorld' DecodedString:HelloWorld RelatedArticle-PythonDecodingDecodeURLinPythonRelatedArticle-PythonUTF-8DecodeURLinPythonConvertXMLtoCSVUsingPythonLinkedListinPythonx



請為這篇文章評分?