新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:Pythoncopy()
python 中的copy()函數(shù)有助于創(chuàng)建集合的副本。我們可以說它返回了一個淺拷貝,這意味著新集合中的任何更改都不會反映原始集合。

我們提供的服務有:做網(wǎng)站、網(wǎng)站設計、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認證、大峪ssl等。為數(shù)千家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務,是有科學管理、有技術的大峪網(wǎng)站制作公司
**set.copy()**
復制()參數(shù):
copy()方法不接受任何參數(shù)。
復制()返回值
有時我們使用=運算符來復制集合,不同之處在于' = '運算符創(chuàng)建對集合的引用,而copy()創(chuàng)建新的集合。
| 投入 | 返回值 | | 設置 | 淺拷貝 |
Python 中copy()方法的示例
示例copy()方法如何對 Python 中的集合起作用?
alphabet = {'a', 'b', 'c'}
new_set = alphabet .copy()
new_set.add(d)
print('Alphabets : ', alphabet )
print('New Set: ', new_set)
輸出:
Alphabets: {'a', 'b', 'c'}
New Set : {'a', 'b', 'c', 'd'} 示例 2:在 Python 中,copy()方法如何使用=運算符處理集合?
alphabet = {'a', 'b', 'c'}
new_set = alphabet
new_set.add(d)
print('Alphabets : ', alphabet )
print('New Set: ', new_set)
輸出:
Alphabets: {'a', 'b', 'c'}
New Set : {'a', 'b', 'c', 'd'} 新聞標題:創(chuàng)新互聯(lián)Python教程:Pythoncopy()
文章分享:http://www.5511xx.com/article/cddgcoo.html


咨詢
建站咨詢
