What will be the output of the following Python code?
>>> a={1,2,3}
>>> b=a.add(4)
>>> b
None
{1,2,3,4}
{1,2,3}
Nothing is printed
>>> b=frozenset([3,4,5])
>>> a-b
{1,2}
Error as difference between a set and frozenset can’t be found out
Error as unsupported operand type for set data type
frozenset({1,2})
>>> a={5,6,7} >>> sum(a,5)
5
23
18
Invalid syntax for sum method, too many arguments
>>> {x*2 for x in a|{4,5}}
{2,4,6}
Error, set comprehensions aren’t allowed
{8, 2, 10, 4, 6}
{8,10}
>>> a={5,6,7,8}
>>> b={7,8,9,10}
>>> len(a+b)
8
Error, unsupported operand ‘+’ for sets
6
Nothing is displayed
Is the following Python code valid?
a={1,2,3}
b={1,2,3,4}
c=a.issuperset(b)
print(c)
False
True
Syntax error for issuperset() method
Error, no method called issuperset() exists
s=set()
type(s)
<’set’>
<class ‘set’>
set
class set
keys, keys
key values, keys
keys, key values
key values, key values
s={abs}
s={4, ‘abc’, (1,2)}
s={2, 2.2, 3, ‘xyz’}
s={san}
s={2, 5, 6, 6, 7}
s
{2, 5, 7}
{2, 5, 6, 7}
{2, 5, 6, 6, 7}
Error
Write a list comprehension for number and its cube for:
l=[1, 2, 3, 4, 5, 6, 7, 8, 9]
[x**3 for x in l]
[x^3 for x in l]
[x**3 in l]
[x^3 in l]
s={1, 2, 3}
s.update(4)
{1, 2, 3, 4}
{1, 2, 4, 3}
{4, 1, 2, 3}
pop
remove
update
sum
s={4>3, 0, 3-3}
all(s)
any(s)
True False
False True
True True
False False
x | y
x ^ y
x & y
x – y
What will be the output of the following Python code snippet?
z=set('abc$de') 'a' in z
No output
z=set('abc')
z.add('san') z.update(set(['p', 'q']))
z
{‘abc’, ‘p’, ‘q’, ‘san’}
{‘a’, ‘b’, ‘c’, [‘p’, ‘q’], ‘san}
{‘a’, ‘c’, ‘c’, ‘p’, ‘q’, ‘s’, ‘a’, ‘n’}
{‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’}
{a**2 for a in range(4)}
{1, 4, 9, 16}
{0, 1, 4, 9, 16}
{0, 1, 4, 9}
. What will be the output of the following Python code?
s1={3, 4}
s2={1, 2} s3=set() i=0 j=0 for i in s1: for j in s2: s3.add((i,j)) i+=1 j+=1
print(s3)
{(3, 4), (1, 2)}
{(4, 2), (3, 1), (4, 1), (5, 2)}
{(3, 1), (4, 2)}
discard
dispose