What is the concept of Python set and how to use it
In this article, the editor introduces in detail "what is the concept of Python set and how to use it", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "what is the concept of Python collection and how to use it" can help you solve your doubts.
The collection is unordered and mutable, and elements cannot be repeated.
In fact, the bottom layer of the collection is the dictionary implementation, and all elements of the collection are "key objects" in the dictionary, so they cannot be repeated and unique.
1 Collection creation and deletion
1.1 create collection objects using {} and add elements using the add () method
> a = {3pje 5pr 7} > > a {3pr 5je 7} > a.add (9) > a {9,3pr 5pr 7}
1.2. Use set () to convert iterable objects such as lists, tuples, etc., into collections
If there is duplicate data in the original data, only one is retained
> a = ['axiaxiajiaozhuo'] > b = set (a) > > b {'bongjinmei' axiaojiao`c'}
1.3. Remove () deletes the specified element
Clear () clears the entire collection
> a = {10, 20, 30, 40, 50} > a.remove (20) > a {10, 50, 30}
2 set related operations
Like concepts in mathematics, Python provides operations on sets, such as union, intersection, difference, and so on.
> a = {1meme 3minisxt'} > > b = {'he','it','sxt'} > a | b # union {1p3 he','it'} > aquib # intersection {' sxt'} > amurb # difference {1pc3} > a.union (b) # union {1p3pcxt', 'he' 'it'} > a.intersection (b) # intersection {' sxt'} > a.difference (b) # difference {1,3} read here This article "what is the concept of Python collection and how to use it" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.