Python encode () method
description
Encoding format string Python encode () method to specify the encoding. errors parameter can specify a different error handling scheme.
grammar
encode () method syntax:
str.encode(encoding='UTF-8',errors='strict')
parameter
- encoding - To use the code, such as "UTF-8".
- errors - set a different error handling scheme. The default is 'strict', meaning a coding error caused UnicodeError. Other values may have to have 'ignore', 'replace', 'xmlcharrefreplace' 'backslashreplace' and no value registered by codecs.register_error ().
return value
This method returns a string encoded.
Examples
The following example shows an example of encode () method:
#!/usr/bin/python str = "this is string example....wow!!!"; print "Encoded String: " + str.encode('base64','strict')
Examples of the above output results are as follows:
Encoded String: dGhpcyBpcyBzdHJpbmcgZXhhbXBsZS4uLi53b3chISE=