issuperset(SetY) and press Enter. The output value of
True
tells you that
SetA
is a
superset of
SetY
. Likewise, if you type SetA.issubset(SetX) and press Enter, you
find that
SetA
is a subset of
SetX
.
It’s important to understand that sets are either mutable or immutable. All the
sets in this example are mutable, which means that you can add or remove ele-
ments from them. For example, if you type SetA.add('Purple') and press Enter,
SetA
receives a new element. If you type SetA.issubset(SetX) and press Enter now,
you find that
SetA
is no longer a subset of
SetX
because
SetA
has the
'Purple'
element in it.
Creating lists
The Python specification defines a list as a kind of sequence. Sequences simply
provide some means of allowing multiple data items to exist together in a single
storage unit, but as separate entities. Think about one of those large mail holders
you see in apartment buildings. A single mail holder contains a number of small
mailboxes, each of which can contain mail. Python supports other kinds of
sequences as well:
Do'stlaringiz bilan baham: |