
When we run above program, it produces the following result −Įncoded String: b'dGhpcyBpcyBzdHJpbmcgZXhhbXBsZS4uLi53b3chISE='ĭecoded String: this is string example. Print "Decoded String: " + Str.decode('base64','strict') This function works based on the parameters specified which are encoding and the error. The encoded string can be decoded and the original string can be obtained with the help of this function. Other possible values are 'ignore', 'replace', 'xmlcharrefreplace', 'backslashreplace' and any other name registered via codecs.register_error(). The python string decode () method decodes the string using the codec registered for its encoding. The default for errors is 'strict', meaning that encoding errors raise a UnicodeError. For a list of all encoding schemes please visit − Standard Encodings.Įrrors − This may be given to set a different error handling scheme. Python String encode () Method String Methods Example Get your own Python Server UTF-8 encode the string: txt 'My name is Ståle' x txt. Str.decode(encoding = 'UTF-8',errors = 'strict')Įncoding − This is the encodings to be used. The python string decode () method decodes the string using the codec registered for its encoding. 08 means width 8, 0 padded, and the b functions as a sign to output the resulting number in base 2 (binary). The right hand side of the colon is the format specifier.
Python string decode code#
Syntaxįollowing is the syntax for decode() method − Using the Python ord () function gives you the base-10 code point for a single str character.



Python String encode () Method Syntax: Syntax: encode (encoding, errors) Parameters: encoding: Specifies the encoding on the basis of which encoding has to be performed. It defaults to the default string encoding. Python String encode () converts a string value into a collection of bytes, using an encoding scheme specified by the user. The decode() method decodes the string using the codec registered for encoding.
