码迷,mamicode.com
首页 > 编程语言 > 详细

python基础数据类型之set(集合)

时间:2017-02-26 08:25:09      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:python之set

set(集合)   set中的数据是唯一的,set中的数据可以改变

  1. 创建set

li=set({"hello","nice"})     //如果创建一个空的,只能li=set()
li={"hello","nice"}

m=["hello","nice"]
li=set(m)  //通过一个可迭代来创建set

2.set的一些方法

    a.difference(b)  //a和b都是set    返回的是在a中,不在b中的元素   a,b不改变 
    a.difference_update(b) //返回值是none,a的值变成在a中不在b中的元素
    a.intersection(b) //a和b的交集


本文出自 “11184009” 博客,请务必保留此出处http://11194009.blog.51cto.com/11184009/1901243

python基础数据类型之set(集合)

标签:python之set

原文地址:http://11194009.blog.51cto.com/11184009/1901243

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!