⊗pyPmStOEA 110 of 208 menu

Adding an Element to a Set in Python

Although it is not possible to add an element by its index, it is still possible to increase the number of elements in a set. This is done using the add method. Its parameter specifies the element to be added.

Let us have a set:

st = {'a', 'b', 'c', 'd'}

Let's add a new element to it:

st.add('e') print(st) # {'a', 'd', 'e', 'c', 'b'}

If you try to add the same element again, the set will remain the same. Since it cannot contain duplicates:

st.add('a') print(st) # {'d', 'c', 'b', 'a'}

Given a set:

st = {1, 2, 3}

Add one more element to this set.

Given variables:

txt1 = 'xyz' txt2 = 'xzy' txt3 = 'xyz'

Add them sequentially to the set from the previous task. Output the resulting set to the console.

frkaenmsuzc