Python 3.1 快速導覽 - 字典的 fromkeys()

字典 (dictionary) 型態 (type) 的 fromkeys() 方法 (method) ,由 seq 中的元素構成 key ,每個 key 都給相同的 value 值

方法描述
classmethod dict.fromkeys(seq[, value])由 seq 中的元素構成 key ,每個 key 都給相同的 value 值


舉例示範如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
d1 = dict.fromkeys("12345")
print(d1)
print()
 
d2 = dict.fromkeys("12345", "abcde")
print(d2)
print()
 
d3 = dict.fromkeys("12345", 0)
print(d3)
print()
 
# 《程式語言教學誌》的範例程式
# 檔名:fromkeys.py
# 功能:示範 Python 程式
# 作者:張凱慶
# 時間:西元 2010 年 12 月


執行結果如下



中英文術語對照
字典dictionary
型態type
方法method


內建型態




沒有留言: