William126

Python实战之set学习笔记及简单练习

['__and__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__iand__', '__init__', '__init_subclass__', '__ior__', '__isub__', '__iter__', '__ixor__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__or__', '__rand__', '__reduce__', '__reduce_ex__', '__repr__', '__ror__', '__rsub__', '__rxor__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__xor__', 'add', 'clear', 'copy', 'difference', 'difference_update', 'discard', 'intersection', 'intersection_update', 'isdisjoint', 'issubset', 'issuperset', 'pop', 'remove', 'symmetric_difference', 'symmetric_difference_update', 'union', 'update']

 

 

# set是一个无序且不重复的元素集合

name = set(['zhangsan','lisi','wangermazi','xiaotaoqi'])
name2 = set(('zhangsan','lisi','wangermazi','xiaotaoqi','william'))
name3 = {'wangermazi', 'xiaotaoqi', 'zhangsan', 'lisi'}
# print(dir(name))
# print(name)
# print(name2)
# print(name3)
# {'xiaotaoqi', 'wangermazi', 'zhangsan', 'lisi'}

# print(name.add('william'))
# {'xiaotaoqi', 'wangermazi', 'lisi', 'william', 'zhangsan'}

# name.clear()
# set()
#
# print(name.copy())
# {'wangermazi', 'xiaotaoqi', 'zhangsan', 'lisi'}

# print(name2.difference(name))
# {'william'}

# print(name.difference_update(name2))
# None
# print(name2)
# {'xiaotaoqi', 'william', 'lisi', 'zhangsan', 'wangermazi'}
# print(name)
# set()
#
# print(name2.difference_update(name))
# print(name2)
# print(name)
# None
# {'william'}
# {'wangermazi', 'xiaotaoqi', 'zhangsan', 'lisi'}

# print(name2.discard('lisi2'))
# print(name.intersection(name2))
# {'wangermazi', 'lisi', 'xiaotaoqi', 'zhangsan'}


# print(name2.intersection_update(name))
# print(name2)
# {'lisi', 'wangermazi', 'xiaotaoqi', 'zhangsan'}
# {'lisi', 'wangermazi', 'xiaotaoqi', 'zhangsan'}


# print(name.isdisjoint(name2))
# False

# print(name2.issubset(name))
# print(name.issubset(name2))
# False
# True

# print(name.issuperset(name2))
# print(name2.issuperset(name))
# False
# True

# print(name.pop())
# zhangsan
# print(name.remove('lisi'))

# print(name.symmetric_difference(name2))
# {'william'}

# print(name2.symmetric_difference(name))
# {'william'}
# print(name)
# print(name.symmetric_difference_update(name2))
# print(name)
# print(name2.symmetric_difference_update(name))
print("*"*20)

# print(name2)
# print(name2.symmetric_difference_update(name))
# print(name2)

# print(name.union(name2))
# {'lisi', 'wangermazi', 'xiaotaoqi', 'william', 'zhangsan'}

# print(name.update(name2))
#
# {'william', 'xiaotaoqi', 'wangermazi', 'lisi', 'zhangsan'}


# print(name.__and__(name2))
# print(name&name2)
# {'lisi', 'xiaotaoqi', 'zhangsan', 'wangermazi'}
# {'lisi', 'xiaotaoqi', 'zhangsan', 'wangermazi'}

# print(name2.__contains__(name))
#
# print(name.__contains__(name2))
#
# print(name.__contains__('lisi'))
# False
# False
# True
#
dict = {'name':123}
print(dir(dict))





print("*"*20)
print(name2)
print(name)

 

posted on 2017-07-02 14:01  William126  阅读(202)  评论(0编辑  收藏  举报

导航