find in set python code example
Example 1: checking if a value is in a set python
thisset = {"apple", "banana", "cherry"}
if "apple" in thisset:
print("Yes, 'apple' is in this set")
Example 2: python sets
my_set = {}
my_set = set()
set_example = {1,3,2,5,3,6}
print(set_example)
Example 3: sets in python
The simplest way to create set is:
1. from list
code:
s = [1,2,3]
set = set(s)
print(set)
2. s,add() method
code:
set.add(1)
set.add(2)
set.remove(2)
print(set) // 1
3. Set conatins unique elements
Example 4: python set
set_example = {1, 2, 3, 4, 5, 5, 5}
print(set_example)
Example 5: set in python
A_Set = {1, 2, "hi", "test"}
for i in A_Set:
print(i)