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
Which of the following is not the correct syntax for creating a set?
a) set([[1,2],[3,4]])
b) set([1,2,2,3,4])
c) set((1,2,3,4))
d) {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))
a) 7
b) Error, invalid syntax for formation of set
c) 4
d) 8
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=" ")
a) 5 5 6
b) 5 6 7
c) 5 5 6 7 7 7
d) 5 6 7 7 7
Which of the following statements is used to create an empty set?
a) { }
b) set()
c) [ ]
d) ( )
What will be the output of the following Python code?
--> a={5,4}
--> b={1,2,4,5}
-->a<b
a) {1,2}
b) True
c) False
d) Invalid operation
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
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
What will be the output of the following Python code?
--> a={4,5,6}
--> b={2,8,6}
--> a+b
a) {4,5,6,2,8}
b) {4,5,6,2,8,6}
c) Error as unsupported operand type for sets
d) 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
a) {4,5}
b) {6}
c) Error as unsupported operand type for set data type
d) 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,8}
--> b={7,8,10,11}
--> ab
a) {5,6,7,8,10,11}
b) {7,8}
c) Error as unsupported operand type of set data type
d) {5,6,10,11}
What will be the output of the following Python code?
--> s={5,6}
--> s*3
a) Error as unsupported operand type for set data type
b) {5,6,5,6,5,6}
c) {5,6}
d) Error as multiplication creates duplicate elements which isn’t allowed
What will be the output of the following Python code?
--> a={5,6,7,8}
--> b={7,5,6,8}
--> a==b
a) True
b) False
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}
Is the following Python code valid?
a={3,4,{7,5}} print(a[2][0])
a) Yes, 7 is printed
b) Error, elements of a set can’t be printed
c) Error, subsets aren’t allowed
d) Yes, {7,5} is printed
What is the data type of (1)?
a) Tuple
b) Integer
c) List
d) Both tuple and integer
If a=(1,2,3,4), a[1:-1] is _________
a) Error, tuple slicing doesn’t exist
b) [2,3]
c) (2,3,4)
d) (2,3)
What will be the output of the following Python code?
--> a=(1,2,(4,5))
--> b=(1,2,(3,4))
--> a<b
a) False
b) True
c) Error, < operator is not valid for tuples
d) Error, < operator is valid for tuples but not if there are sub-tuples
What will be the output of the following Python code?
--> a=("Check")*3
--> a
a) (‘Check’,’Check’,’Check’)
b) * Operator not valid for tuples
c) (‘CheckCheckCheck’)
d) Syntax error
What will be the output of the following Python code?
--> a=(1,2,3,4)
--> del(a[2])
a) Now, a=(1,2,4)
b) Now, a=(1,3,4)
c) Now a=(3,4)
d) Error as tuple is immutable
What will be the output of the following Python code?
a=(2,3,4)
--> sum(a,3)
a) Too many arguments for sum() method
b) The method sum() doesn’t exist for tuples
c) 12
d) 9
Is the following Python code valid?
a=(1,2,3,4)
del a
a) No because tuple is immutable
b) Yes, first element in the tuple is deleted c) Yes, the entire tuple is deleted
d) No, invalid syntax for del method
What type of data is:
a=[(1,1),(2,4),(3,9)]? a) Array of tuples
b) List of tuples
c) Tuples of lists
d) Invalid type
What will be the output of the following Python code?
a=(0,1,2,3,4)
b=slice(0,2)
-->a
a) Invalid syntax for slicing
b) [0,2]
c) (0,1)
d) (0,2)
Is the following Python code valid?
--> a=(1,2,3)
--> b=('A','B','C')
--> c=zip(a,b)
a) Yes, c will be ((1,2,3),(‘A’,’B’,’C’))
b) Yes, c will be ((1,2,3),(‘A’,’B’,’C’))
c) No because tuples are immutable
d) No because the syntax for zip function isn’t valid