निम्नलिखित कोड का आउटपुट क्या है?
What is the output of following code ?
a=set('abc')
b=set('cd')
print(a^b)
A)
B)
C)
D)
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
a
is{'a', 'b', 'c'}
. - Set
b
is{'c', 'd'}
. a ^ b
is the symmetric difference of setsa
andb
, which includes all elements that are in eithera
orb
but 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'}