Set Add in Python
Level 258 keystrokes
This adds a new element to a set using the add() method. Sets contain unique elements only.
Python code
# Create a set with two colors1colors = {"red", "blue"}# add() inserts a new element into the set# If element already exists, nothing happens2colors.add("green")# Print the set (order may vary)3print(colors)Output
{'red', 'blue', 'green'}Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this Python code and how often they appear.
"× 6(× 2)× 2,× 1.× 1{× 1}× 1=× 1