Question 1 of 25
Hints left: 3
Q1
How can you add an element to a set in Python?
Q2
Is the following Python code valid? >>> a=(1,2,3) >>> b=a.update(4,)
-
A
-
B
-
C
-
D
Q3
What will be the output of the following Python code snippet? s=set([1, 2, 3]) s.union([4, 5]) s|([4, 5])
-
A
-
B
-
C
-
D
Q4
What will be the output of the following Python code? >>>t=(1,2,4,3) >>>t[1:3]
Q5
What is the output of the following code: my_set = {1, 2, 3} print(my_set)
Q6
What will be the output of the following Python code snippet? a=[1, 4, 3, 5, 2] b=[3, 1, 5, 2, 4] a==b set(a)==set(b)
Q7
Which of the following data types in Python is mutable and does not allow duplicate elements?
Q8
What is the purpose of the clear() method for sets?
Q9
What will be the output of the following Python code? >>> a=(1,2) >>> b=(3,4) >>> c=a+b >>> c
Q10
Is the following Python code valid? >>> a,b=1,2,3
Q11
In Python, how can you check if an element exists in a set?
Q12
What does the len() function do when applied to a set or tuple?
Q13
Which method is used to find the intersection of two sets?
Q14
What is the output of the following code: my_set = {1, 2, 3, 4, 5} my_set.pop() print(my_set)
-
A
-
B
-
C
-
D
Q15
Is the following Python code valid? >>> a=2,3,4,5 >>> a
-
A
-
B
-
C
-
D
Q16
What will be the output of the following code: my_set = {1, 2, 3} my_set.add(4) print(my_set)
-
A
-
B
-
C
-
D
Q17
What method is used to remove an element from a set without raising an error if the element is not present?
Q18
What will be the output of the following Python code? >>>t = (1, 2, 4, 3, 8, 9) >>>[t[i] for i in range(0, len(t), 2)]
-
A
-
B
-
C
-
D
Q19
Which method is used to remove an element from a set?
Q20
What will be the output of the following Python code? >>> a=(1,2,(4,5)) >>> b=(1,2,(3,4)) >>> a<b
Q21
What is the purpose of the union() method for sets?
Q22
What is the purpose of the set() constructor in Python?
Q23
What is the output of the following code: my_set = {1, 2, 3} my_set.remove(2) print(my_set)
Q24
What will be the output of the following Python code? >>> a={3,4,5} >>> a.update([1,2,3]) >>> a
Q25
What is the output of the following code: set1 = {1, 2, 3} set2 = {1, 2} print(set1.issuperset(set2))