Python | Sets

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"))
for e in s:
print("total element are:",count-1) 
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.

#blog #interview #placement #learn #computer #science

11 views0 comments

Recent Posts

See All

        Contact Us

  • LinkedIn
  • Facebook
  • Instagram

©2023 by Programmers Door