Python String decode() Method - Tutorialspoint

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

Description. Python string method decode() decodes the string using the codec registered for encoding. It defaults to the default string encoding. Home CodingGround Jobs Whiteboard Tools Business Teachwithus PythonBasicTutorial Python-Home Python-Overview Python-EnvironmentSetup Python-BasicSyntax Python-VariableTypes Python-BasicOperators Python-DecisionMaking Python-Loops Python-Numbers Python-Strings Python-Lists Python-Tuples Python-Dictionary Python-Date&Time Python-Functions Python-Modules Python-FilesI/O Python-Exceptions PythonAdvancedTutorial Python-Classes/Objects Python-RegExpressions Python-CGIProgramming Python-DatabaseAccess Python-Networking Python-SendingEmail Python-Multithreading Python-XMLProcessing Python-GUIProgramming Python-FurtherExtensions PythonUsefulResources Python-QuestionsandAnswers Python-QuickGuide Python-Tools/Utilities Python-UsefulResources Python-Discussion SelectedReading UPSCIASExamsNotes Developer'sBestPractices QuestionsandAnswers EffectiveResumeWriting HRInterviewQuestions ComputerGlossary WhoisWho PythonStringdecode()Method Advertisements PreviousPage NextPage  BeyondBasicProgramming-IntermediatePython MostPopular 36Lectures 3hours MohammadNauman MoreDetail PracticalMachineLearningusingPython BestSeller 91Lectures 23.5hours MANASDASGUPTA MoreDetail PracticalDataScienceusingPython 22Lectures 6hours MANASDASGUPTA MoreDetail Description Pythonstringmethoddecode()decodesthestringusingthecodecregisteredforencoding.Itdefaultstothedefaultstringencoding. Syntax Str.decode(encoding='UTF-8',errors='strict') Parameters encoding−Thisistheencodingstobeused.Foralistofallencodingschemespleasevisit:StandardEncodings. errors−Thismaybegiventosetadifferenterrorhandlingscheme.Thedefaultforerrorsis'strict',meaningthatencodingerrorsraiseaUnicodeError.Otherpossiblevaluesare'ignore','replace','xmlcharrefreplace','backslashreplace'andanyothernameregisteredviacodecs.register_error(). ReturnValue Decodedstring. Example LiveDemo #!/usr/bin/python Str="thisisstringexample....wow!!!"; Str=Str.encode('base64','strict'); print"EncodedString:"+Str print"DecodedString:"+Str.decode('base64','strict') Result EncodedString:dGhpcyBpcyBzdHJpbmcgZXhhbXBsZS4uLi53b3chISE= DecodedString:thisisstringexample....wow!!! python_strings.htm PreviousPage PrintPage NextPage  Advertisements



請為這篇文章評分?