collection of python

There is no index to re-order


#remove remove elements

>>> s1 = {1,2,3,4,5}
>>> s1.remove(2)
>>> print(s1)
{1, 3, 4, 5}

 

#pop Cut

>>> s1 = {1,2,3,4,5}
>>> res = s1.pop()
>>> print(res)
1

 

Add #add

>>> s1 = {1,2,3,4,5}
>>> s1.add('250')
>>> print(s1)
{1, 2, 3, 4, 5, '250'}

 

#update add new elements

>>> s1 = {1,2,3,4,5}
>>> s1.update('1','2','8','9')
>>> print(s1)
{1, 2, 3, 4, 5, '9', '1', '2', '8'}

 

# Determines whether the set is a subset of another set

>>> s1 = {1,2,3,4,5}
>>> s2 = {1,2,3}
>>> res = s2.issubset(s1)
>>> print(res)
True

 

#union union

>>> s1 = {1,2,3,4,5}
>>> s2 = {1,2,3,7}
>>> print(s2.union(s1))
{1, 2, 3, 4, 5, 7}

 

#intersection intersection

>>> s1 = {1,2,3,4,5}
>>> s2 = {1,2,3,7}
>>> print(s1.intersection(s2))
{1, 2, 3}

 

Guess you like

Origin www.cnblogs.com/t-ym/p/11824808.html