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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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)

 

以上是关于Python实战之set学习笔记及简单练习的主要内容,如果未能解决你的问题,请参考以下文章

Python实战之双向队列deque/queue学习笔记及简单练习

Python实战之正则表达式RE/re学习笔记及简单练习

Python3《机器学习实战》学习笔记

NoSQL学习笔记之——Redis基础

Python实战之dict简单练习

Python3学习笔记-字典及列表练习