Python 3.1 快速導覽 - 集合的 copy()

集合 (set) 與原封集合 (frozenset) 型態 (type) 的 copy() 方法 (method) ,回傳 s 的拷貝

方法描述
s.copy()回傳 s 的拷貝


舉例示範如下
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
a = {"a", "b", "c"}
print(a)
print(type(a))
print()
 
b = a.copy()
print(b)
print(type(b))
print("a == b: ", a == b)
print()
 
c = b.copy()
print(c)
print(type(c))
print("c == a: ", c == a)
print("c == b: ", c == b)
print()
 
 
# 《程式語言教學誌》的範例程式
# 檔名:copy.py
# 功能:示範 Python 程式
# 作者:張凱慶
# 時間:西元 2010 年 12 月


執行結果如下



中英文術語對照
集合set
原封集合frozenset
型態type
方法method


內建型態




沒有留言: