0

Why is the output different?

a = {10, 20, 30, 40} b = {40, 50, 60, 70} a.difference(b) print(a) c = a.difference(b) print(c) output: {40, 10, 20, 30} {10, 20, 30}

25th Oct 2022, 7:51 AM
Shantanu
Shantanu - avatar
1 Answer
+ 5
a.difference(b) => will not reflect changes by operation on original sets, it returns a new result set. So first time output is same as original set a. 2nd time, your are storing result of operation into variable c... so c is result of operation..... Note: set doesnot maintain order of insertion of elements..
25th Oct 2022, 8:21 AM
Jayakrishna 🇼🇳