June 2020
Intermediate to advanced
382 pages
11h 39m
English
A set is defined as a collection of elements that can be of different types. The elements are enclosed within { }. For example, have a look at the following code block:
>>> green = {'grass', 'leaves'}>>> print(green){'grass', 'leaves'}
The defining characteristic of a set is that it only stores the distinct value of each element. If we try to add another redundant element, it will ignore that, as illustrated in the following:
>>> green = {'grass', 'leaves','leaves'}>>> print(green){'grass', 'leaves'}
To demonstrate what sort of operations can be done on sets, let's define two sets:
A set named yellow, which has things that are yellow
Another set named red, which has things that are red
Note that some things are common between these ...
Read now
Unlock full access