In Python, set set is one of the basic data types, and it has both mutable set (set) and immutable set (Frozenset). creating Set Sets, collection set additions , collection deletions , intersections , sets , and difference sets is a very useful approach.
1. Create a Collection
The set class is in Python's sets module, and you are now using the python2.3 that you do not need to import sets modules to create the collection directly.
>>>set (' Boy ')
Set ([' Y ', ' b ', ' O '])
2. Collection Add, delete
There are two common methods for adding a collection, namely add and update.
Collection Add method: The element to be passed in as an entire add to the collection, for example:
>>> a = set (' Boy ')
>>> a.add (' python ')
>>> A
Set ([' Y ', ' python ', ' B ', ' O '])
Collection Update method: Splits the element to be passed in as an individual into the collection, for example:
>>> a = set (' Boy ')
>>> a.update (' python ')
>>> A
Set ([' B ', ' H ', ' o ', ' n ', ' P ', ' t ', ' Y '])
Collection Delete Action method: remove
Set ([' Y ', ' python ', ' B ', ' O '])
>>> a.remove (' python ')
>>> A
Set ([' Y ', ' b ', ' O '])
Traversal of the 3.SET collection
Traverse set:
Def iterset (): s = set ([]) for item in s: print (item) for I in enumerate (s): print (i)
4.python set operation symbols, mathematical symbols
The intersection of the collection, the collection (and set), and the difference set, to understand these very useful functions of collection set, we should first understand some of the collection operation symbols
(This image is from the network)
A simple demonstration of the concept of the difference set, intersection, and collection:
set sets are unordered and cannot be manipulated by indexes and slices
Python Collection Set Add Delete, Intersect, set, set operation symbols