In Python set is a collection type of the base data type, which has both a mutable set (set ()) and an immutable set (Frozenset). Creating Set Sets, collection set additions , collection deletions , intersections , sets , and difference sets is a very useful approach.
Create Collection Set
The Python set class is in Python's sets module, and you are now using the python2.7.x that you do not need to import sets modules to create the collection directly.
>>>set (' Boy ')
Set ([' Y ', ' b ', ' O '])
Collection Add, delete
There are two common methods for adding Python collections, 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 '])
Python set () Set operation symbols, mathematical symbols
The intersection of the collection, the collection (and set), and the difference set, to understand the Python collection set and list of these very useful features, you should first understand some of the collection operation symbols
A simple demonstration of the concept of the difference set, intersection, and collection:
The variable collection python set is the www.iplaypy.com Python learning communication platform, which is more accessible in early Python learning. An iterative pair of images such as lists, dictionaries, and strings can be used as parameters to a collection. Set sets are unordered and cannot be manipulated by indexes and slices.
Python Collection Set () add Delete, intersect, set, set operation details