Python programming
Python programming
SETS
MADE BY :
IKSHU MISHRA
ROLL NO.
23/BAP/094
PYTHON SETS
* A set is an unordered collection of items. Every element
is unique and must be immutable.
• Sets are mutable. But since they are unordered, indexing have no meaning.
• We cannot access or change an element of set using indexing or slicing.
• We can add single element using the add() method and multiple elements using
the update() method.
• The update() method can take tuples, lists, strings or other sets as its argument. In
all cases, duplicates are avoided.
REMOVE ELEMENTS FROM A
SET
• A particular item can be removed from set using methods, discard() and
removed().
• using discard() if the item does not exist in the set , it remains unchanged
• but remove () will raise an error in such conditions.
SET MEMBERSHIP
TEST
• we can test , if an item exists in a set or not , using the in
operator
• given an list of elements, remove the
dupliicate element.
Read a string and find the
numbers of unique characters
in it
PYTHON SET
OPERATIONS
• sets can be used to carry out mathematical set operations like union,
intersection, difference and symmetrical difference
• We can do this with operators and methods.
SET MUTATION
OPERATIONS
• we have seen the applications of union , intersection, difference and
symmetric difference operations but these operations do not make
any changes or mutations to the set.
• we can use the following operations to create mutations to
a set.
THANK YOU