What will be the output of the following Python code? s1={1, 2, 3} s2={3, 4, 5, 6} s1.difference(s2) s2.difference(s1)
Question
What will be the output of the following Python code?
s1 = {1, 2, 3}
s2 = {3, 4, 5, 6}
s1.difference(s2)
s2.difference(s1)
Solution
The output of the Python code will be:
For s1.difference(s2)
, the output will be {1, 2}
. This is because the difference()
method returns a set that contains the difference between two sets. The difference between s1
and s2
is {1, 2}
because these are the elements that exist in s1
but not in s2
.
For s2.difference(s1)
, the output will be {4, 5, 6}
. This is because the difference between s2
and s1
is {4, 5, 6}
because these are the elements that exist in s2
but not in s1
.
Similar Questions
What will be the output of the following Python code?s1={1, 2, 3}s2={4, 5, 6}s1.isdisjoint(s2)s2.isdisjoint(s1)
What will be the output of the following Python code snippet?a=[1, 4, 3, 5, 2]b=[3, 1, 5, 2, 4]a==bset(a)==set(b)
What would be the output of the following Python statement?set1={1,2,3}set2={4,5,6}set3 = set1.union(set2)set3
What do these 3 lines print?>>> s1 = "Best School">>> s2 = s1>>> print(s1 == s2)
What is the output of below code snippeta = [ [8, 2] , [4, 1, 2, 2] ]b = a[1][2:]print(b)
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.