Created
March 27, 2024 18:41
-
-
Save makwanadeepam/330e4a6fbd4ba7a8fed78d18e148b8d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s: set={1,2,3,4,5,55,5} | |
print(s) | |
# for loop | |
for i in s: | |
print(i) | |
# add, remove, clear, discard | |
s.add(33) | |
print(s) | |
s.remove(4) | |
print(s) | |
s.clear() | |
print(s) | |
s={1,2,3,4,5,55} | |
s1={2,3,4} | |
print(s.difference(s1)) | |
s.discard(55) # Doesn't raise error if element doesn't exist | |
print(s) | |
# union intersection | |
print(s.intersection(s1)) | |
print(s.union(s1)) | |
# membership and pop | |
print(5 in s) | |
s.pop() # Takes no arguments | |
print(s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment