In Python, the in keyword is used to check if an element exists in a set. It returns a boolean value (True or False) based on whether the element is present in the set or not
Check Membership
mySet = {1, 2, 3, 4, 5}
# Check if an element exists in the set
print(3 in mySet) # Output: True
print(6 in mySet) # Output: False
if 4 in mySet:
print(True) # Output: True
else:
print(False)
Loops in Set
mySet = {1, 2, 3, 4, 5}
for element in mySet:
print(element) # Output: 1, 2, 3, 4, 5, 6