|
A set is a collection which is unordred and unindexed in a way that we cannot be sure in which order the items will appear.
|
RYB_color = {"Red","Yellow","Blue"} |
RYB_color = set(("Red","Yellow","Blue")) |
|
Example 1
for x in RYB_color: Example 2 print("Yellow" in RYB_color) |
|
Since a set is not orderer neither indexed, then we cannot acces to any item to change its value.
|
RYB_color.add("White") |
print(len(RYB_color)) |
del RYB_color |
RYB_color.remove("Yellow") |
|
|
If the item doesn't exist then
remove() will raise an error. |
|
RYB_color.discard("Yellow") |
|
|
If the item doesn't exist then
discard() will raise an error. |
|
c = thisset.pop() |
|
|
Since a set is not orderer neither indexed, then we cannot change acces to any item to change its value.
|
|
RYB_color.clear() |
|
clear() returns an empty set. |
Second_color = {"Green","Orange","Purple"} |
|
union() joins two sets into a new one and excludes any duplicate items. |
|
RYB_color.update(Second_color) |
|
update() inserts the items in Second_color into RYB_color and excludes any duplicate items. |
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.