Python Test 6 - Sets Which of these about a set is not true? Allows duplicate values Mutable data type Immutable data type Data type with unordered values Which of the following is not the correct syntax for creating a set? {1,2,3,4} set((1,2,3,4)) set([1,2,2,3,4]) set([[1,2],[3,4]]) What will be the output of the following Python code? nums = set([1,1,2,3,3,3,4,4]) print(len(nums)) 4 8 7 Error, invalid syntax for formation of set 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=" ") 5 5 6 5 6 7 5 6 7 7 7 5 5 6 7 7 7 Which of the following statements is used to create an empty set? set() { } [ ] ( ) What will be the output of the following Python code? a={5,4} b={1,2,4,5} a<b {1,2} Invalid operation False True If a={5,6,7,8}, which of the following statements is false? a[2]=45 a.remove(5) print(min(a)) print(len(a)) If a={5,6,7}, what happens when a.add(5) is executed? a={5,6,7} a={5,5,6,7} Error as there is no add function for set data type Error as 5 already exists in the set What will be the output of the following Python code? a={4,5,6} b={2,8,6} a+b {4,5,6,2,8,6} {4,5,6,2,8} Error as unsupported operand type for sets Error as the duplicate item 6 is present in both sets What will be the output of the following Python code? a={4,5,6} b={2,8,6} a-b {4,5} {6} Error as the duplicate item 6 is present in both sets Error as unsupported operand type for set data type What will be the output of the following Python code? a={5,6,7,8} b={7,8,10,11} a^b {5,6,10,11} {5,6,7,8,10,11} {7,8} Error as unsupported operand type of set data type What will be the output of the following Python code? s={5,6} s*3 Error as unsupported operand type for set data type Error as multiplication creates duplicate elements which isn’t allowed View Answer {5,6,5,6,5,6} {5,6} What will be the output of the following Python code? a={5,6,7,8} b={7,5,6,8} a==b True False What will be the output of the following Python code? a={3,4,5} b={5,6,7} a|b Invalid operation {5} {3,4,6,7} {3, 4, 5, 6, 7} Is the following Python code valid? a={3,4,{7,5}} print(a[2][0]) Yes, {7,5} is printed Error, subsets aren’t allowed Error, elements of a set can’t be printed Yes, 7 is printed Schreibe einen Kommentar Antworten abbrechenDu musst angemeldet sein, um einen Kommentar abzugeben.