Python String encode() Method


Contents

Description

The encode() method in Python String is known to return an encoded version of the string. The current default string encoding is the default encoding. The errors might be given to set of varied error handling schemes.

Syntax

str.encode(encoding='UTF-8',errors='strict')

Parameters

  • encoding − This is the encodings which are to be used. For a list of complete encoding schemes please visit the Standard Encodings.
  • errors − This may be provided to set varied error handling scheme. The default for errors is 'strict', meaning that encoding errors raise a UnicodeError. Other possible values are 'ignore', 'xmlcharrefreplace', 'replace', 'backslashreplace' and many other name which is registered through codecs.register_error().

Return Value

Decoded string.

Example

#!/usr/bin/python

str = "this is string example....wow!!!";
print "Encoded String: " + str.encode('base64','strict')

Result

Encoded String: dGhpcyBpcyBzdHJpbmcgZXhhbXBsZS4uLi53b3chISE=

Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.



Navigation
Tutorial
Tutorial
Tutorial