Printing differences between lists/tuples/sets

Hello All

I am printing the following 3 statements using lists/tuples/sets. While the output of lists/tuples are similar, output of set is different. Kindly let me know why there is a difference

my_list = ["Valmiki","Vasishta","Kashyapa","Vishvamitra"]
my_tuple = ("Valmiki","Vasishta","Kashyapa","Vishvamitra")
my_set = {"Valmiki","Vasishta","Kashyapa","Vishvamitra"}

print(my_list)

[‘Valmiki’, ‘Vasishta’, ‘Kashyapa’, ‘Vishvamitra’]

print(my_tuple)

(‘Valmiki’, ‘Vasishta’, ‘Kashyapa’, ‘Vishvamitra’)

print(my_set)

{‘Vishvamitra’, ‘Vasishta’, ‘Kashyapa’, ‘Valmiki’}

Thanks
Harish

1 Like

Hi @hari.yajurveda,
It’s because sets are unordered.
So, when you print the same set for a number of times, there is a fair chance that the output will not be in the same order.

1 Like