/  Python-Sets-Quiz

This Quiz contains totally 10 Questions each carry 1 point for you.

1.What will the below Python code do?
set1={"a",3,"b",3}
set1.remove(3)

 
It removes element with index position 3 from set1
It removes element 3 from set1
It removes only the first occurrence of 3 from set1
No such function exists for set

Correct!

Wrong!

2.Select which is true for Python sets
Sets are unordered and do not allow duplicates
Sets are ordered
Set allow duplicate
a set object does support indexing

Correct!

Wrong!

3.Which of the following is not the correct syntax for creating a set?
set([[1,2],[3,4]])
set([1,2,2,3,4])
set((1,2,3,4))
{1,2,3,4}

Correct!

Wrong!

4.Which of the following statements is used to create an empty set?
{ }
set()
[ ]
( )

Correct!

Wrong!

5.What is the output of the following?
sampleSet = {"Yellow", "Orange", "Black"}
sampleSet.add("Blue")
sampleSet.add("Orange")
print(sampleSet)
{‘Blue’, ‘Orange’, ‘Yellow’, ‘Orange’, ‘Black’}
{‘Blue’, ‘Orange’, ‘Yellow’, ‘Black’}

Correct!

Wrong!

6.Which of the following options will give an error if set1={2,3,4,5}?
print(set1[0])
set1[0]=9
set1=set1+{7}
All of the above

Correct!

Wrong!

7.Set members must not be hashable.
True
False

Correct!

Wrong!

8.What will be the output of the following Python code?
a={1,2,3}
b=a.add(4)
b
0
{1,2,3,4}
{1,2,3}
Nothing is printed

Correct!

Wrong!

9.Suppose a set sis defined as follows

s = {'A', 'B', 'C', 'D'}

Which of the following remove element 'B' from s:
s &= {'A', 'B', 'D'}
del s['B']
s.discard('B')
s.pop()

Correct!

Wrong!

10.What is the output of the following program?
A = {0, 2, 4, 6, 8}; 
B = {1, 2, 3, 4, 5};
print(A & B)
{2, 4}
{0, 1, 2, 3, 4, 5, 6, 8}
{0, 1, 3, 5, 6, 8}
{0, 8, 6}

Correct!

Wrong!

Share the quiz to show your results !

Subscribe to see your results

Ignore & go to results

Python-Sets-Quiz

You got %%score%% of %%total%% right

%%description%%

%%description%%

Where to go ?

Quizzes

Loading...