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

語法
set 語法:
class set([iterable])
參數(shù)說明:
iterable -- 可迭代對象對象;
返回值
返回新的集合對象。
實例
以下實例展示了 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),免費的在線學(xué)習(xí)python平臺,歡迎關(guān)注!
文章題目:創(chuàng)新互聯(lián)Python教程:python中set是什么
網(wǎng)站地址:http://www.5511xx.com/article/cdhjsos.html


咨詢
建站咨詢
