-
Book Overview & Buying
-
Table Of Contents
The Python Workshop
By :
So far, in this chapter, you have covered lists, dictionaries, and tuples. You can now have a look at sets, which are another type of Python data structure.
Sets are a relatively new addition to the Python collection type. They are unordered collections of unique and immutable objects that support operations mimicking mathematical set theory. As sets do not allow multiple occurrences of the same element, they can be used to effectively prevent duplicate values.
A set is a collection of objects (called members or elements). For instance, you can define set A as even numbers between 1 to 10, and it will contain {2,4,6,8,10}, and set B can be odd numbers between 1 to 10, and it will contain {1,3,5,7,9}. In the following exercise, you will get our hands on sets in Python:
Figure 2.21: Set A and Set B – each set contains a unique, distinct value
In this exercise, you will gain an understanding...
Change the font size
Change margin width
Change background colour