設置 copy() 方法
copy() 方法用於複製集合,它返回一個包含該集合所有元素的集合。
用法:
set_name.copy()
參數:
- 它不接受任何參數。
返回值:
這個方法的返回類型是<class 'set'>
,它返回一個包含這個集合的副本的集合。
例:
# Python Set copy() Method with Example
# declaring a set
cities = {"New Delhi", "Mumbai", "Indore", "Gwalior"}
# creating another set by using
# copy() method
x = cities.copy()
# printing both sets
print("cities:", cities)
print("x:", x)
輸出
cities: {'New Delhi', 'Mumbai', 'Indore', 'Gwalior'} x: {'New Delhi', 'Mumbai', 'Indore', 'Gwalior'}
相關用法
- Python Set clear()用法及代碼示例
- Python Set issuperset()用法及代碼示例
- Python Set difference_update()用法及代碼示例
- Python Set union()用法及代碼示例
- Python Set pop()用法及代碼示例
- Python Set add()用法及代碼示例
- Python Set issubset()用法及代碼示例
- Python Set update()用法及代碼示例
- Python Set isdisjoint()用法及代碼示例
- Python Set intersection_update()用法及代碼示例
- Python Set symmetric_difference()用法及代碼示例
- Python Set symmetric_difference_update()用法及代碼示例
- Python Set discard()用法及代碼示例
- Python Set intersection()用法及代碼示例
- Python Set difference()用法及代碼示例
- Python Set remove()用法及代碼示例
- Python Pandas Series.cummin()用法及代碼示例
- Python Pandas Series.cov()用法及代碼示例
- Python Pandas Series.astype()用法及代碼示例
- Python Pandas Series.mad()用法及代碼示例
注:本文由純淨天空篩選整理自 Python Set copy() Method with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。