The difference between the functions discard and remove is that:
1. Discard removes the last element of the set whereas remove removes the first element of the set
2.Discard throws an error if the specified element is not present in the set whereas remove does not throw an error in case of absence of the specified element
3. Remove removes the last element of the set whereas discard removes the first element of the set
4.Remove throws an error if the specified element is not present in the set whereas discard does not throw an error in case of absence of the specified element
The following Python code results in an error. s={2, 3, 4, [5, 6]}
1. True
2. False
3.None of the above
4.all of the mentioned
What will be the output of the following Python code snippet? {a**2 for a in range(4)}
1.{1, 4, 9, 16}
2. {0, 1, 4, 9, 16}
3.Error
4.{0, 1, 4, 9}
What will be the output of the following Python code? >>> a={1,2,3} >>> a.intersection_update({2,3,4,5}) >>> a
1. {2,3}
2. Error, duplicate item present in list
3.Error, no method called intersection_update for set data type
4.{1,4,5}
What will be the output of the following Python code? >>> a={3,4,5} >>> a.update([1,2,3]) >>> a
1. Error, no method called update for set data type
2. {1, 2, 3, 4, 5}
3.Error, list can’t be added to set
4.Error, duplicate item present in list
What will be the output of the following Python code? >>> a={3,4,5} >>> b={5,6,7} >>> a|b
1.Invalid operation
2.{3, 4, 5, 6, 7}
3.{5}
4. {3,4,6,7}
What will be the output of the following Python code? >>> a={4,5,6} >>> b={2,8,6} >>> a-b
1. {4,5}
2. {6}
3. Error as unsupported operand type for set data type
4. Error as the duplicate item 6 is present in both sets
What will be the output of the following Python code? >>> a={5,6,7} >>> sum(a,5)
1.5
2.23
3.18
4.Invalid syntax for sum method, too many arguments
What will be the output of the following Python code? a={1,2,3} b={1,2,3} c=a.issubset(b) print(c)
1.True
2. Error, no method called issubset() exists
3.Syntax error for issubset() method
4. False
What will be the output of the following Python code? s={2, 5, 6, 6, 7} s
1.{2, 5, 7}
2. {2, 5, 6, 7}
3. {2, 5, 6, 6, 7}
4.error
Which of the following functions will return the symmetric difference between two sets, x and y?
1. x | y
2.x ^ y
3.x & y
4. x – y
Which of the following statements create a dictionary?
1.d = {}
2.d = {“johnâ€:40, “peterâ€:45}
3.d = {“johnâ€:40, “peterâ€:45}
4.all of the mentioned
Which of these about a frozenset is not true?
1.Mutable data type
2.Allows duplicate values
3. Data type with unordered values
4.Immutable data type
If a={5,6,7,8}, which of the following statements is false?
1. print(len(a))
2. print(min(a))
3.a.remove(5)
4. a[2]=45
If a={5,6,7}, what happens when a.add(5) is executed?
1. a={5,5,6,7}
2.a={5,6,7}
3.Error as there is no add function for set data type
4.Error as 5 already exists in the set
If we have two sets, s1 and s2, and we want to check if all the elements of s1 are present in s2 or not, we can use the function:
1. s2.issubset(s1)
2. s2.issuperset(s1)
3.s1.issuperset(s2)
4.s1.isset(s2)
Is the following Python code valid? a={1,2,3} b={1,2,3,4} c=a.issuperset(b) print(c)
1. False
2.True
3.Syntax error for issuperset() method
4.Error, no method called issuperset() exists
Is the following Python code valid? a={3,4,{7,5}} print(a[2][0])
1.Yes, 7 is printed
2.Error, elements of a set can’t be printed
3.Error, subsets aren’t allowed
4.Yes, {7,5} is printed
Is the following Python code valid? >>> a=frozenset([5,6,7]) >>> a >>> a.add(5)
1.Yes, now a is {5,5,6,7}
2.No, frozen set is immutable
3. No, invalid syntax for add method
4.Yes, now a is {5,6,7}
Set makes use of ____ Dictionary makes use of ______
1. keys, keys
2.key values, keys
3.keys, key values
4.key values, key values
Suppose d = {“johnâ€:40, “peterâ€:45}, to delete the entry for “john†what command do we use?
1.d.delete(“johnâ€:40)
2.d.delete(“johnâ€)
3. del d[“johnâ€]
4.del d(“johnâ€:40)
Suppose d = {“johnâ€:40, “peterâ€:45}. To obtain the number of entries in dictionary which command do we use?
1.d.size()
2.len(d)
3.size(d)
4. d.len()
The output of the following code is: class<’set’>. type({})
1. True
2. False
3.Both a & b
4.None of these
The ______ function removes the first element of a set and the last element of a list.
1.remove
2. pop
3.discard
4.dispose
What is the syntax of the following Python code? >>> a=frozenset(set([5,6,7])) >>> a
1. {5,6,7}
2.frozenset({5,6,7})
3.Error, not possible to convert set into frozenset
4.Syntax error
What will be the output of the following Python code snippet? d = {"john":40, "peter":45} d["john"]
1.40
2.45
3.“johnâ€
4.“peterâ€
What will be the output of the following Python code snippet? d = {"john":40, "peter":45} print(list(d.keys()))
1. [“johnâ€, “peterâ€]
2.[“johnâ€:40, “peterâ€:45]
3.(“johnâ€, “peterâ€)
4. (“johnâ€:40, “peterâ€:45)
What will be the output of the following Python code snippet? d = {"john":40, "peter":45}
1. “johnâ€, 40, 45, and “peterâ€
2.“john†and “peterâ€
3.40 and 45
4.d = (40:â€johnâ€, 45:â€peterâ€)
What will be the output of the following Python code snippet? d1 = {"john":40, "peter":45} d2 = {"john":466, "peter":45} d1 > d2
1.True
2.False
3.Error
4.None of these
What will be the output of the following Python code snippet? d1 = {"john":40, "peter":45} d2 = {"john":466, "peter":45} d1 == d2
1.True
2.False
3. None
4.error
What will be the output of the following Python code snippet? z=set('abc') z.add('san') z.update(set(['p', 'q'])) z
1. {‘abc’, ‘p’, ‘q’, ‘san’}
2. {‘a’, ‘b’, ‘c’, [‘p’, ‘q’], ‘san}
3. {‘a’, ‘c’, ‘c’, ‘p’, ‘q’, ‘s’, ‘a’, ‘n’}
4. {‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’}
What will be the output of the following Python code? >>> a={1,2,3} >>> b=a >>> b.remove(3) >>> a
1. {1,2,3}
2.Error, copying of sets isn’t allowed
3. {1,2}
4.Error, invalid syntax for remove
What will be the output of the following Python code? >>> a={1,2,3} >>> b=a.add(4) >>> b
1. 0
2.{1,2,3,4}
3.{1,2,3}
4. Nothing is printed
What will be the output of the following Python code? >>> a={1,2,3} >>> b=a.copy() >>> b.add(4) >>> a
1. {1,2,3}
2.Error, invalid syntax for add
3. {1,2,3,4}
4.Error, copying of sets isn’t allowed
What will be the output of the following Python code? >>> a={1,2,3} >>> b=frozenset([3,4,5]) >>> a-b
1. {1,2}
2.Error as difference between a set and frozenset can’t be found out
3. Error as unsupported operand type for set data type
4. frozenset({1,2})
What will be the output of the following Python code? >>> a={1,2,3} >>> {x*2 for x in a|{4,5}}
1. {2,4,6}
2.Error, set comprehensions aren’t allowed
3. {8, 2, 10, 4, 6}
4.{8,10}
What will be the output of the following Python code? >>> a={4,5,6} >>> b={2,8,6} >>> a+b
1.{4,5,6,2,8}
2.{4,5,6,2,8,6}
3.Error as unsupported operand type for sets
4.Error as the duplicate item 6 is present in both sets
What will be the output of the following Python code? >>> a={5,4} >>> b={1,2,4,5} >>> a<b
1.{1,2}
2.True
3.False
4.Invalid operation
What will be the output of the following Python code? >>> a={5,6,7,8} >>> b={7,8,10,11} >>> a^b
1. {5,6,7,8,10,11}
2. {7,8}
3.Error as unsupported operand type of set data type
4. {5,6,10,11}
What will be the output of the following Python code? >>> a={5,6,7,8} >>> b={7,8,9,10} >>> len(a+b)
1.8
2. Error, unsupported operand ‘+’ for sets
3.6
4. Nothing is displayed
What will be the output of the following Python code? >>> s={5,6} >>> s*3
1.Error as unsupported operand type for set data type
2.{5,6,5,6,5,6}
3.{5,6}
4.Error as multiplication creates duplicate elements which isn’t allowed
What will be the output of the following Python code? a = [5,5,6,7,7,7] b = set(a) def test(lst): if lst in b: return 1 else: return 0 for i in filter(test, a): print(i,end=" ")
1. 5 5 6
2. 5 6 7
3. 5 5 6 7 7 7
4.5 6 7 7 7
What will be the output of the following Python code? s=set() type(s)
1. <’set’>
2. <class ‘set’>
3.set
4. class set
What will be the output of the following Python code? s={1, 2, 3} s.update(4) s
1.{1, 2, 3, 4}
2.{1, 2, 4, 3}
3.{4, 1, 2, 3}
4.error
What will be the output of the following Python code? nums = set([1,1,2,3,3,3,4,4]) print(len(nums))
1.7
2.Error, invalid syntax for formation of set
3.4
4.8
Which of the following functions cannot be used on heterogeneous sets?
1. pop
2.remove
3.update
4.sum
Which of the following is not the correct syntax for creating a set?
1.set([[1,2],[3,4]])
2. set([1,2,2,3,4])
3.set((1,2,3,4))
4. {1,2,3,4}
Which of the following lines of code will result in an error?
1.s={abs}
2.s={4, ‘abc’, (1,2)}
3.s={2, 2.2, 3, ‘xyz’}
4.s={san}
Which of the following statements is used to create an empty set?
1.{ }
2.set()
3.[ ]
4. ( )
Write a list comprehension for number and its cube for: l=[1, 2, 3, 4, 5, 6, 7, 8, 9]
1.[x**3 for x in l]
2.[x^3 for x in l]
3. [x**3 in l]
4. [x^3 in l]