January 2019
Beginner
318 pages
8h 23m
English
A set is an unordered collection of elements with no duplicates. The basic use of a set is to check membership testing and eliminate duplicate entries. These set objects support mathematical operations, such as union, intersection, difference, and symmetric difference. We can create a set using curly braces or the set() function. If you want create an empty set, then use set(), not {}.
Here is a brief demonstration:
>>> fruits = {'Mango', 'Apple', 'Mango', 'Watermelon', 'Apple', 'Orange'}>>> print (fruits){'Orange', 'Mango', 'Apple', 'Watermelon'}>>> 'Orange' in fruitsTrue>>> 'Onion' in fruitsFalse>>>>>> a = set('abracadabra')>>> b = set('alacazam')>>> a{'d', 'c', 'r', 'b', 'a'}>>> a - b{'r', 'd', 'b'}>>> a | b{'d', 'c', 'r', 'b', 'm', ...Read now
Unlock full access