Python 的 copy 方法用于将一组项复制到一个全新的集合中,其语法为
set.copy()
在此示例中,我们声明了一个水果集合。接下来,我们使用此 copy 函数将 fruits 复制到 copy_of_fruit 中。
fruits_set = {'Mango', 'Cherry', 'Apple', 'Kiwi'}
print('The Original Set : ', fruits_set )
copy_of_fruits_set = fruits_set.copy()
print('The Copied Set : ', copy_of_fruits_set )

这次我们对数字集合使用 copy 函数
numeric = {15, 25, 35, 45, 55}
print('The Original : ', numeric )
copy_of_numeric = numeric.copy()
print('The Copied : ', copy_of_numeric )
The Original : {35, 55, 25, 45, 15}
The Copied : {35, 55, 25, 45, 15}