Python Sets Quiz

Last Updated :
Discuss
Comments

Question 1

What is the output of the following program?

Python
set1 = {1, 2, 3, 4, 4} 
print(set1) 
  • A

    {1, 2, 3}

  • B

    {1, 2, 3, 4}

  • C

    {1, 2, 3, 4, 4}

  • D

    Error

Question 2

What is the output of the following program?

Python
set1 = {3, 4, 5} 
set1.update([1, 2, 3]) 
print(set1) 
  • A

    {1, 2, 3, 4, 5}

  • B

    {3, 4, 5, 1, 2, 3}

  • C

    {1, 2, 3, 3, 4, 5}

  • D

    Error

Question 3

What is the output of the following program?

Python
set1 = {1, 2, 3} 
set2 = set1.copy() 
set2.add(4) 
print(set1) 
  • A

    {1, 2, 3, 4}

  • B

    {1, 2, 3}

  • C

    Invalid Syntax

  • D

    Error

Question 4

What is the output of the following program?

Python
set1 = {1, 2, 3} 
set2 = set1.add(4) 
print(set2) 
  • A

    {1, 2, 3, 4}

  • B

    {1, 2, 3}

  • C

    Invalid Syntax

  • D

    None

Question 5

What is the output of the following program?

Python
set1 = {1, 2, 3} 
set2 = {4, 5, 6} 
print(len(set1 + set2)) 
  • A

    3

  • B

    6

  • C

    Unexpected

  • D

    Error

Question 6

What is the output of the following program?

Python
set1 = {0, 2, 4, 6, 8}; 
set2 = {1, 2, 3, 4, 5}; 

print(set1 | set2) 
  • A

    {0, 1, 2, 3, 4, 5}

  • B

    {0, 1, 2, 3, 4, 5, 6, 8}

  • C

    { 6, 8}

  • D

    None

Question 7

What is the output of the following program?

Python
set1 = {0, 2, 4, 6, 8}; 
set2 = {1, 2, 3, 4, 5}; 


print(set1 & set2) 
  • A

    {0, 1, 2, 3, 4, 5, 6, 8}

  • B

    {0, 1, 3, 5, 6, 8}

  • C

    {2, 4}

  • D

    {0, 8, 6}

Question 8

What is the output of the following program?

Python
set1 = {0, 2, 4, 6, 8}; 
set2 = {1, 2, 3, 4, 5}; 

print(set1 - set2)
  • A

    {0, 1, 2, 3, 4, 5, 6, 8}

  • B

    {0, 8, 6}

  • C

    {2, 4}

  • D

    {0, 1, 3, 5, 6, 8}

Question 9

What is the output of the following program?

Python
set1 = {0, 2, 4, 6, 8}; 
set2 = {1, 2, 3, 4, 5}; 

print(set1 ^ set2) 
  • A

    {0, 1, 2, 3, 4, 5, 6, 8}

  • B

    {2, 4}

  • C

    {0, 8, 6}

  • D

    {0, 1, 3, 5, 6, 8}

Question 10

What is the output of the following program?

Python
set1 = set([1, 2, 4, 4, 3, 3, 3, 6, 5]) 

print(set1) 
  • A

    {1, 2, 4, 4, 3, 3, 3, 6, 5}

  • B

    {1, 2, 3, 4, 5, 6}

  • C

    [1, 2, 3, 4, 5, 6]

  • D

    [1, 2, 4, 4, 3, 3, 3, 6, 5]

There are 11 questions to complete.

Take a part in the ongoing discussion