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

Python decode() method

Python decode() method

Python Strings Python Strings


Description

The Python decode() method decodes a string using encoding the specified encoding. The default encoding is the string encoding.

Syntax

Syntax of the decode() method:


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

Parameters

Return Value

This method returns the decoded string.

Example

The following example demonstrates the decode() method:

Example (Python 3.0+)

#!/usr/bin/python

str

=

"

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

"

;

str

=

str

.

encode

(

'

base64

'

,

'

strict

'

)

;

print

"

Encoded String:

"

str

;

print

"

Decoded String:

"

str

.

decode

(

'

base64

'

,

'

strict

'

)

The output of the above example is:


Encoded String: dGhpcyBpcyBzdHJpbmcgZXhhbXBsZS4uLi53b3chISE=

Decoded String: this is string example....wow!!!

Python Strings Python Strings