1. Which of these about a set is not true?
A. Mutable data type
B. Allows duplicate values
C. Data type with unordered values
D. Immutable data type
Ans : Immutable data type
2. Which of the following statements is used to create an empty set?
A. { }
B. set()
C. [ ]
D. ( )
Ans : set()
3. If a={5,6,7,8}, which of the following statements is false?
A. print(len(a))
B. print(min(a))
C. a.remove(5)
D. a[2]=45
Ans : a[2]=45
4. What will be the output of the following Python code?
>>> a={3,4,5}
>>> b={5,6,7}
>>> a|b
A. Invalid operation
B. {3, 4, 5, 6, 7}
C. {5}
D. {3,4,6,7}
Ans : {3,4,5,6,7}
5. If a={5,6,7}, what happens when a.add(5) is executed?
A. a={5,5,6,7}
B. a={5,6,7}
C. Error as there is no add function for set data type
D. Error as 5 already exists in the set
Ans : a={5,6,7}
6. What will be the output of the following Python code?
nums = set([1,1,2,3,3,3,4,4])
print(len(nums))
A. 7
B. Error, invalid syntax for formation of set
C. 4
D. 8
Ans : 4
7. Which of these about a frozenset is not true?
A. Mutable data type
B. Allows duplicate values
C. Data type with unordered values
D. Immutable data type
Ans : Mutable data type
8. Set members must not be hashable.
A. True
B. False
Ans : False
9. What will be the output of the following Python code?
>>> a={1,2,3}
>>> a.intersection_update({2,3,4,5})
>>> a
A. {2,3}
B. Error, duplicate item present in list
C. Error, no method called intersection_update for set data type
D. {1,4,5}
Ans : {2,3}
10. Is the following Python code valid?
>>> a=frozenset([5,6,7])
>>> a
>>> a.add(5)
A. Yes, now a is {5,5,6,7}
B. No, frozen set is immutable
C. No, invalid syntax for add method
D. Yes, now a is {5,6,7}
Ans : No,frozen set is immutable
11. What will be the output of the following Python code?
>>> a={1,2,3}
>>> b=a
>>> b.remove(3)
>>> a
A. {1,2,3}
B. Error, copying of sets isn’t allowed
C. {1,2}
D. Error, invalid syntax for remove
Ans : {1,2}
12. What will be the output of the following Python code?
>>> a={1,2,3}
>>> b=a.add(4)
>>> b
A. 0
B. {1,2,3,4}
C. {1,2,3}
D. Nothing is printed
Ans : Nothing is printed
13. What will be the output of the following Python code?
>>> a={5,6,7,8}
>>> b={7,8,9,10}
>>> len(a+b)
A. 8
B. Error, unsupported operand ‘+’ for sets
C. 6
D. Nothing is displayed
Ans : Error, unsupported operand '+' for sets
14. Which of the following functions cannot be used on heterogeneous sets?
A. pop
B. remove
C. update
D. sum
Ans : sum
15. What will be the output of the following Python code?
s=set()
type(s)
A. <’set’>
B. <class ‘set’>
C. set
D. class set
Ans : <class 'set'>
16. Input order is preserved in sets.
A. True
B. False
Ans : False
17. Set makes use of __________
Dictionary makes use of ____________
A. keys, keys
B. key values, keys
C. keys, key values
D. key values, key values
Ans : keys, key values
18. Which of the following functions will return the symmetric difference between two sets, x and y?
A. x | y
B. x ^ y
C. x & y
D. x – y
Ans : x ^ y
19. What will be the output of the following Python code, if s1= {1, 2, 3}?
s1.issubset(s1)
A. True
B. Error
C. No output
D. False
Ans : True
20. The ____________ function removes the first element of a set and the last element of a list.
A. remove
B. pop
C. discard
D. dispose
Ans : pop
1 Comments
👍👍
ReplyDelete