Easy Tutorial
❮ Python Func Number Hypot Python Execute String Code ❯

Python3 bytes.decode() Method

Python3 Strings


Description

The decode() method decodes the bytes object using the specified encoding. The default encoding is 'utf-8'.

Syntax

The syntax for the decode() method is:

bytes.decode(encoding="utf-8", errors="strict")

Parameters

Return Value

This method returns the decoded string.

Example

The following example demonstrates the use of the decode() method:

Example (Python 3.0+)

#!/usr/bin/python3

str = "tutorialpro.org";
str_utf8 = str.encode("UTF-8")
str_gbk = str.encode("GBK")

print(str)

print("UTF-8 Encoding:", str_utf8)
print("GBK Encoding:", str_gbk)

print("UTF-8 Decoding:", str_utf8.decode('UTF-8','strict'))
print("GBK Decoding:", str_gbk.decode('GBK','strict'))

The output of the above example is:

tutorialpro.org
UTF-8 Encoding: b'\xe8\x8f\x9c\xe9\xb8\x9f\xe6\x95\x99\xe7\xa8\x8b'
GBK Encoding: b'\xb2\xcb\xc4\xf1\xbd\xcc\xb3\xcc'
UTF-8 Decoding: tutorialpro.org
GBK Decoding: tutorialpro.org

Python3 Strings

❮ Python Func Number Hypot Python Execute String Code ❯