#gather #Set definition method Braces {} and set se={1,2,3} #The collection is unordered, and there cannot be repeated elements, and it is variable. #The collection is unordered, so each return order is returned randomly, and the collection has no index #Set the most important uses, and cross #& The intersection returns the same elements of the two sets, if there are no identical elements, it returns the empty value of the empty value set() #| Union removes duplicates from two sets and forms a new set #- The difference set is to remove the common part of the two sets and form a new set. For example, the a set - the b set displays the result that the a set removes the duplicates of the b set, and any elements in the b set will not appear in the new set. in the collection. # If you don't understand the difference set, see the example below se={1,2,3} s2={'a',1,2,3} s2-se ''' {'a'} ''' se-s2 ''' set() ''' #Common methods of collection # pop randomly removes an element in the set, because the set is unordered, so pop cannot pass in coordinates. Deletion is random # remove specifies to delete an element se.remove(2) deletes 2 in the se set # update can add multiple values at once # add adds one value at a time # QQ:8131432
Collection of Python Basics
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=325801082&siteId=291194637
Recommended
Ranking