Python 3.1 快速導覽 - 字節型態的 decode()

字節 (bytes) 型態 (type) 的 decode() 方法 (method) ,將 bytes 解譯為指定編碼的字串

方法描述
bytes.decode(encoding="utf-8", errors="strict")將 bytes 解譯為指定編碼的字串


舉例示範如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
a = b"Free your mind."
print(a)
print(a.decode())
print()
 
b = b"Welcome to the desert... of the real."
print(b)
print(b.decode())
print()
 
c = b"What is real? How do you define real?"
print(c)
print(c.decode())
print()
 
d = b"There is no spoon."
print(d)
print(d.decode())
print()
 
# 《程式語言教學誌》的範例程式
# 檔名:bytesdecode.py
# 功能:示範 Python 程式
# 作者:張凱慶
# 時間:西元 2010 年 12 月


執行結果如下



中英文術語對照
字節bytes
型態type
方法method


內建型態




沒有留言: