集合1

什么是集合:由不同的元素组成,集合中的元素排列无序,集合必 须是不可变类型(数字,字符串)

集合的创建:

s = {'hello','world','python','python','jalor'} #集合,输出时会进行去重,因为为不同元素
drict = {s:'hello',m:'max',y:'yellow'}#字典

type的作用:type类型转换

利用set函数直接定义集合

s = set('hello')
print (s) 
{'h','o','l','e'}
####
s = set(['hello','hello','world'])
print (s)
>>{'hello','world'}
#集合中的内置方法 add(),clear(),copy(),pop()随机删除,remove(self,x)指定删除,discard()也是制定删除但不会报错

猜你喜欢

转载自www.cnblogs.com/LittleGreenOrc/p/9490537.html