Let's analyze the code step by step:
socialMedias = set()
-
This initializes an empty set called socialMedias.
socialMedias.add("Threads")socialMedias.add("Twitter")
-
Adds "Threads" and "Twitter" to the set.
socialMedias.add("YouTube")socialMedias.add("YouTube")
-
The first add("YouTube") adds "YouTube" to the set.
-
The second add("YouTube") has no effect because sets do not allow duplicate values.
socialMedias.remove("YouTube")
-
Removes "YouTube" from the set. After this, "YouTube" is no longer in socialMedias.
print(len(socialMedias))
-
The remaining elements in the set are {"Threads", "Twitter"}.
-
The length of the set is 2.
Output:
2
0 Comments:
Post a Comment