The ten collections of the zero-basic introduction to Python first remember several features of the set: the set is unordered, and the elements in the set are unique.
1. set definition
The definition of a set is very similar to that of a dictionary. you only need to convert the key-value pairs in the dictionary into elements.
Num = {1, 2, 3, 4, 5} print (type (num) print ("\ n") # Duplicate data is automatically removed from the set, and the set is also unordered num2 = {1, 2, 3, 4, 5, 4, 32} print (num2) print ("\ n ")
(2) use the set () factory function
Set1 = set ([1, 2, 3, 4, 5, 6]) print (set1)
(3) use frozenset () to create an unchangeable set: Once a set is created, the set cannot be modified; otherwise, an exception occurs.
Num3 = frozenset ([1, 2, 3, 4, 5]) num3.add (6)
The above is a set of 10 things for getting started with Python. For more information, see The PHP Chinese website (www.php1.cn )!