Original address: Http://docs.pythontab.com/python/python3.4/datastructures.html#tut-tuples
A collection is a set of unordered, non-repeating elements.
Basic features include relationship testing and elimination of duplicate elements. The collection object also supports mathematical operations such as Union (union), intersection (intersection), Difference (poor), and sysmmetric difference (symmetric difference sets).
Curly braces or set () functions can be used to create collections.
Note: To create an empty collection, you must use set () instead of {}. The latter is used to create an empty dictionary.
>>> Basket = {'Apple','Orange','Apple','Pear','Orange','Banana'}>>>Print(basket)#show that duplicates has been removed{'Orange','Banana','Pear','Apple'}>>>'Orange' inchBasket#Fast Membership TestingTrue>>>'Crabgrass' inchBasketfalse>>>#demonstrate set operations on the unique letters from the words...>>> A = set ('Abracadabra')>>> B = Set ('Alacazam')>>> A#unique letters in a{'a','R','b','C','D'}>>> A-B#letters in a and not in B{'R','D','b'}>>> A | B#letters in either A or B{'a','C','R','D','b','m','Z','L'}>>> A & B#letters in both A and B{'a','C'}>>> a ^ b#letters in A or B and not both{'R','D','b','m','Z','L'}
Python data structure-set set