What are the characteristics of Python collection
This article will explain in detail what characteristics Python collection has, Xiaobian thinks it is quite practical, so share it with you as a reference, I hope you can gain something after reading this article.
1. The order of internal elements is not guaranteed, and there are no duplicate elements. Union, subtraction and intersection operations can be performed.
2, the collection has disorder, it is impossible to know the specific position of an element in the collection, and it is impossible to slice the collection.
Collections can be created using braces {} or the set() function.
However, if you want to create an empty collection, you cannot use {} because {} is used to create an empty dictionary.
examples
Example: set1={"java","c++","c","c","python"} print(set1) //I output the result here as {'java', 'c++', 'python',' c'}, you can see that only one of the two c's is output; at the same time, due to the disorder of the set, the order between the elements of this output result will also change. set2={"java1","c++","c","c","python"} print(set1-set2) //Compute difference set, output {'java'} print(set1| set2) //Compute union, output {'c','c++', 'java 1','python', 'java'} print(set1&set2) //Compute intersection, output {'c++', 'python', 'c'} //Again, the set is unordered, so don't worry about the appearance of different outputs. About "Python collection what characteristics" this article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.