w3resource logo


Python Exercises

Python Exercise: Add member in a set

Python sets: Exercise-3 with Solution

Write a Python program to add member(s) in a set.

Sample Solution :-

Python Code :

#A new empty set
color_set = set()
color_set.add("Red")
print(color_set)
#Add multiple items
color_set.update(["Blue", "Green"])
print(color_set)

Output :

{'Red'}
{'Green', 'Red', 'Blue'}

Python Code Editor:

#A new empty set
color_set = set()
color_set.add("Red")
print(color_set)
#Add multiple items
color_set.update(["Blue", "Green"])
print(color_set)

Improve this sample solution and post your code through Disqus.



Join our Question Answer community to learn and share your programming knowledge.

Solve these problems:

Python: How to check whether a file exists using Python?

C#: Loops in c#

PHP: For each

SQL: JOIN using more than 5 tables

JavaScript: Blank Slide in Javascript Slideshow