1, dict
Unordered, can be changed
2. tuple
Ordered, unchangeable
3, list
Orderly, can be changed (add, delete)
4, set
Disordered, may change
{element 1, element 2, element 3.....} are defined with curly brackets like the dictionary, but the difference is that there is no colon separation, there is another definitionThe method is to pass any sequence to the set() function (such as a string set('fsdaf'))
Operation of 2 sets:
The set in python is the same as the set in mathematics. It also has intersection, union, difference and other operations. The union provides the method union(), the difference method difference(), but the difference here is different.It is only possible to display all elements in the collection using this method that are different from another collection, and the method intersection() of the intersection displays the same elements
The following code is used to implement the above method:
#Set operation
temp={'a','e','i','o','u'}
temp2=set("fda");
#Intersection operation
result=temp.intersection(temp2)#{'a'}
#Parallel operation
result=temp.union(temp2)#{'a', 'o', 'f', 'd', 'u', 'e', 'i'}
#Difference operation
result=temp.difference(temp2)#{'o', 'e', 'u', 'i'}
1. Author: Syw
3. The copyright of this article belongs to the author, welcome to reprint, butWithout the consent of the author, this statement must be retained, and the original text link should be given in an obvious position on the article page, otherwise the right to pursue legal responsibility is reserved.
4. If there are any mistakes in the text, please point them out.lest more people be misled.