Python 3 set1.update(set2) - reason for different outputs | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Python 3 set1.update(set2) - reason for different outputs

#my python 3 code set1 = {"a", "b" , "c"} set2 = {1, 2, 3} set1.update(set2) print(set1) _________________________________ {1, 2, 3, 'b', 'c', 'a'} ____________________ {1, 'a', 2, 3, 'c', 'b'} ______________________ {'c', 1, 2, 3, 'b', 'a'} ___________________ I am getting different outputs on every run......can anyone explain its behavior

25th Sep 2019, 2:42 PM
Peter Stark
1 Answer
+ 2
python sets are unordered and unindexed datatype, the order of the set will not be stable hence the different outputs are produced...
26th Sep 2019, 3:54 AM
Ajmal Hussain
Ajmal Hussain - avatar