When writing a program, I used the set() function, so I checked the definition and usage of the set() function
Create a collection set
The python set class is in the sets module of python. In python2.3 you are using now, you can create a set directly without importing the sets module.
>>>set('boy')
set(['y', 'b', 'o'])
Collection add, delete
There are two common methods for adding collections, namely add and update.
Set add method: Add the elements to be passed in as a whole to the set, for example:
>>> a = set('boy')
>>> a.add('python')
>>> a
set( ['y', 'python', 'b', 'o'])
The set update method: it splits the elements to be passed in and passes them into the set as individuals, for example:
>>> a = set( 'boy')
>>> a.update('python')
>>> a
set(['b', 'h', 'o', 'n', 'p', 't', 'y'] )
Set deletion operation method: remove
set(['y', 'python', 'b', 'o'])
>>> a.remove('python')
>>> a
set(['y', ' b', 'o'])
python set() set operation symbols, mathematical symbols
集合的交集、合集(并集)、差集,了解集合set的这些非常好用的功能前,要先了解一些集合操作符号
简单的演示下差集、交集和合集的概念: