Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python encode() method

Python encode() method

Python Strings Python Strings


Description

The Python encode() method encodes a string using encoding the specified encoding. The errors parameter can specify different error-handling schemes.

Syntax

Syntax of the encode() method:


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

Parameters

Return Value

This method returns the encoded string.

Example

The following example demonstrates the encode() method:

Example

#!/usr/bin/python

str

=

"this is string example....wow!!!"

;

print

"Encoded String: "

str

.

encode

(

'base64'

,

'strict'

)

The output of the above example is:


Encoded String: dGhpcyBpcyBzdHJpbmcgZXhhbXBsZS4uLi53b3chISE=

Python Strings Python Strings