Decode UTF-8 in Python | Delft Stack
文章推薦指數: 80 %
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
延伸文章資訊
- 1A Guide to Unicode, UTF-8 and Strings in Python
Sure! Let's see all we have covered so far visually. By default in Python 3, we are on the left s...
- 2Unicode HOWTO — Python 3.10.7 documentation
Python's string type uses the Unicode Standard for representing ... This means that UTF-8 strings...
- 3Python Convert Unicode to Bytes, ASCII, UTF-8, Raw String
Converting Unicode strings to bytes is quite common these days because it is necessary to convert...
- 4Understand the encoding/decoding of Python strings (Unicode ...
UTF-8 is an abbreviation for Unicode Transformation Format — 8 bits. The “8” here means 8-bit blo...
- 5Day27 Python 基礎- 字符轉編碼操作 - iT 邦幫忙
UTF-8 是一種針對Unicode的可變長度字元編碼,英文字符一樣會依照ASCII碼規範,只占一個字節8bit,而中文字符的話,統一就占三個字節. 回顧可以參考字符編碼.