निम्नलिखित कोड का आउटपुट क्या है?
What is the output of following code ?
a=set('abc')
b=set('cd')
print(a^b) A
{a,b,c,d}
B
{'c', 'b', 'a', 'd'}
C
{'b', 'a', 'd'}
D
None of these
Explanation
Let's break down the code:
a = set('abc') # Converts string 'abc' to a set: {'a', 'b', 'c'}
b = set('cd') # Converts string 'cd' to a set: {'c', 'd'}
print(a ^ b) # The symmetric difference between sets a and b
Explanation:
- Set
ais{'a', 'b', 'c'}. - Set
bis{'c', 'd'}. a ^ bis the symmetric difference of setsaandb, which includes all elements that are in eitheraorbbut not in both.
The elements that are in either a or b but not both are:
'a'and'b'from seta.'d'from setb.
So, the result of a ^ b will be {'a', 'b', 'd'}.
Answer:
(C) {'b', 'a', 'd'}
Correct Answer: C) {'b', 'a', 'd'}