集合及深浅copy 01

集合

#集合 可变数据类型,但是存储的元素必须是可变数据类型,无序,不重复!
set1 = set({1,2,3})
#set2 = set(1,2,[2,4],{2,4}) # 错的,必须放可哈希的
print(set1)
print(set2)
View Code

#集合的添加
set1 = set({'suidyai','kjsadfhik','ldsahf'})
set1.add('套你大象')
print(set1)
set2 = {'sdjka','jaksahd'}
set2.update('套你大象')
print(set2)
View Code

#集合的删除
set1 = {'sakdhi','sadhk','sladjsa'}
set1.pop()#随机删除
print(set1.pop())#1有返回值
print(set1)
View Code
set1 = {'sakdhi','sadhk','sladjsa'}
# set1.pop()#随机删除
# print(set1.pop())#1有返回值
# print(set1)
set1.remove('sakdhi')#按元素去删除
print(set1)
View Code

 查

#
set1 = {'sakdhi','sadhk','sladjsa'}
for i in set1:
    print(i)
View Code

 

posted @ 2019-07-23 22:17  套你大象  阅读(75)  评论(0编辑  收藏  举报