Python program to Iterate over sets

#Create a set
num_set = set([0, 1, 2, 3, 4, 5])
for n in num_set:
  print(n, end=' ')
print("\n\nCreating a set using string:")
char_set = set("w3resource")
# Iterating using for loop
for val in char_set:
    print(val, end=' ')

OUTPUT:

0 1 2 3 4 5
Creating a set using string:
c e 3 u r o w s 

Leave a Comment