In python to create a set, we use curly brackets { }.
A set can't be empty there must be any value in the set if you want to create an empty set so you can create in such way s = set( )
To add any value in the set there is a function called (add) you can use this function to add value in set example s.add(4)
Now 4 is added inset to delete a set you can use a function clear as [s.clear( )].
Example program of the set: To count the total elements in a set.
s = set(input("enter n numbers"))
count=0
for e in s:
count+=1
print("total element are:",count-1)
Output:
enter n numbers1,2,3,4,5,6,7,8,9
total element are: 9
Happy Coding!
Follow us on Instagram @programmersdoor
Join us on Telegram @programmersdoor
Please write comments if you find any bug in the above code/algorithm, or find other ways to solve the same problem.
Follow Programmers Door for more.
Comments