Python Sets Quiz

Python Set Quiz

This is a quiz regarding the Python Sets.

Topics covered in this quiz :

  1. Python Sets
  2. Add Item to Set
  3. Remove Item from Set
  4. Loop through Sets
  5. Merge Sets
  6. Set Methods

1) What is the output of the below code?
a = {1,2,3,4}
b = {3,4,1,2}
print(a == b)

2) How can we create the empty set?

3) What is the output of the below code?
a = {1,2,3}
b = {3,4,5,6,7}
print(a-b)

4) What is the output of the below code?
a = {1,2,3}
b = {3,4,5,6,7}
print(a&b)

5) What is the output of the below code?
a = {1,2,3}
b = {3,4,5,6,7}
print(a|b)

6) What is the output of the below code?
a = {1,2,3}
b = {3,4,5,6,7}
print(a^b)

7) What is the output of the following code?

s = {"Bill", "Jack", "Jeff"}
del(s)
print(s)

8) What is the output of the following code?

s = {"Bill", "Jack", "Jeff"}
s.clear
print(s)

9) What is the output of the following code?

my_set = {5,1,8,3,4}
x = sorted(my_set)
print(x)

10) What is the output of the following code?

my_set1 = {5,1,8,3,4}
my_set2 = {}
print(type(my_set1), type(my_set2))

11) What is the output of the following code?

my_set1 = {1,2,3,4}
my_set2 = {1,2,3,4}
my_set3 = {*my_set1, *my_set2}
print(my_set3)

12) What is the output of the following code?

name = set("Logical Python")
print(name[1:3])

13) What is the output of the following code?

s1 = {1,2,3,4}
s2 = {1,2,3,4}
print( id(s1) == id(s2))

14) What is the output of the following code?

my_set = {5,1,8,3,4}
my_set.discard(2)
my_set.remove(2)
print(my_set)

15) What is the output of the following code?

s = {"Bill", "Jack", {"Jeff", "Elon"}}
print(s)

Your score is

The average score is 62%

0%