Tuesday, March 27, 2018

How to add items to a Set?


Adding Items to a Set

We can add elements to a set by using add method. Again as discussed there is no specific index attached to the newly added element.

Days = set(["Mon","Tue","Wed","Thu","Fri","Sat"])

Days.add(“Sun”)
Print (Days)

When the above code is executed, it produces the following result.

set(['Wed', 'Sun', 'Fri', 'Tue', 'Mon', 'Thu', 'Sat'])




<<<  Sets                      Go to Index                   Remove Items >>>