Getting Started
format(SetX, SetY, SetZ)) and press Enter. You see one set printed on each line,
like this:
{'Blue', 'Orange', 'Red', 'Green', 'Black', 'Yellow'}
{'Green', 'Black'}
{'Blue', 'Red'}
The outputs show the results of the math operations:
union()
,
intersection()
,
and
difference()
. Python’s fancier print formatting can be useful in working
with collections such as sets. The
format()
function tells Python which objects to
place within each of the placeholders in the string. A placeholder is a set of curly
brackets ({}) with an optional number in it. The escape character (essentially a kind
of control or special character),
/n
, provides a newline character between entries.
You can read more about fancy formatting at
https://docs.python.org/3/
tutorial/inputoutput.html
.
You can also test relationships between the various sets. For example, type SetA.
Do'stlaringiz bilan baham: |