set Created collection It's a set of elements that don't repeat in disorder , Relationship testing is possible , Delete duplicate data , You can also compute the intersection 、 Difference set 、 And set etc. .
Set operator
Add elements to the collection :
a = {"1", "2", "3"}
a.add("qwq")
print(a)
Like adding elements from a list to a collection :
a = {"1", "2", "3"}
a.update(["qwq","QAQ"])
print(a)
But if update If a single string is written in it, it will be split
a = {"1", "2", "3"}
a.update("QAQ")
print(a)
Get the elements unique to each of the two collections :
a = {"1", "2", "3"}
b = {"1", "4"}
ret = a.symmetric_difference(b)
Delete elements from the collection
a = {"1", "2", "3"}
a.remove("1")
print(a)