新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
創(chuàng)新互聯(lián)Python教程:python中set是什么
SET() 函數(shù)創(chuàng)建一個(gè)無(wú)序不重復(fù)元素集,可進(jìn)行關(guān)系測(cè)試,刪除重復(fù)數(shù)據(jù),還可以計(jì)算交集、差集、并集等。

語(yǔ)法
set 語(yǔ)法:
class set([iterable])
參數(shù)說(shuō)明:
iterable -- 可迭代對(duì)象對(duì)象;
返回值
返回新的集合對(duì)象。
實(shí)例
以下實(shí)例展示了 set 的使用方法:
>>>x = set('runoob')
>>> y = set('google')
>>> x, y
(set(['b', 'r', 'u', 'o', 'n']), set(['e', 'o', 'g', 'l'])) # 重復(fù)的被刪除
>>> x & y # 交集
set(['o'])
>>> x | y # 并集
set(['b', 'e', 'g', 'l', 'o', 'n', 'r', 'u'])
>>> x - y # 差集
set(['r', 'b', 'u', 'n'])
>>>python學(xué)習(xí)網(wǎng),免費(fèi)的在線學(xué)習(xí)python平臺(tái),歡迎關(guān)注!
文章名稱(chēng):創(chuàng)新互聯(lián)Python教程:python中set是什么
分享URL:http://m.fisionsoft.com.cn/article/cdhjsos.html


咨詢
建站咨詢
