varS = {valu1, valu2}
=> Initialize a setvarS = set()
=> Creates a empty setvarS = {}
=> Empty set acts as dictionaryvarS.add(value)
=> Adds in the set, Retains only unique valuesvarS.remove(value)
=> Removes the value given from the set if it is present otherwise throws errorvarS.discard(value)
=> Removes an element from the set if it is presentvarS.pop()
=> Removes and returns an arbitrary element from the setmax(varS)
=> Return maximum element of setmin(varS)
=> Return minimum element of setlen(varS)
=> Return length of setvarS.clear()
=> Removes all elements from the setdel varS
=> Deletes the entire setvarS.copy()
=> Returns a shallow copy of the setvarS.update(varS1)
=> Adds all elements from varS1 to the setvarS.issubset(varS1)
=> Returns True if the set is a subset of varS1varS.issuperset(varS1)
=> Returns True if the set is a superset of varS1varS1.isdisjoint(varS2)
=> Returns True if both sets are disjointvarS.union(varS1)
=> Returns union of varS and the new set givenvarS.difference(varS1)
=> Returns a new set that is the difference between both setsvarS.difference_update(varS1)
=> Removes all elements from the set that are also present in varS1varS.intersection(varS1)
=> Returns intersection of varS and the set givenvarS.intersection_update(varS1)
=> Removes all elements from the set that are not present in varS1varS.symmetric_difference(varS1)
=> Returns a new set that is the symmetric difference between the set and varS1varS.symmetric_difference_update(varS1)
=> Removes all elements from the set that are also present in varS1, and adds all elements that are present in varS1 but not in the set for element in varS:
print(element)
if value in varS:
# statements
else:
# statements