Quizzes

Python Sets Quiz


Welcome to the Python Sets Quiz!

Sets are unordered collections with no duplicate elements. This quiz will test your knowledge of sets in Python, covering concepts such as set operations, properties, and methods.

Each question has one correct answer. Try your best, and let’s see how much you know about sets!

Table of Contents:


Sets Quiz


Questions & Answers

Basic Concepts

1. What is a set in Python?
a) A collection of ordered items
b) A collection of unique and unordered items
c) A mutable list
d) A tuple with unique values

2. Which of the following is the correct way to create an empty set?
a) set = {}
b) set = set()
c) set = []
d) set = {None}

3. What will be the output of {1, 2, 2, 3, 4, 4, 5}?
a) {1, 2, 2, 3, 4, 4, 5}
b) {1, 2, 3, 4, 5}
c) [1, 2, 3, 4, 5]
d) (1, 2, 3, 4, 5)

4. Which of the following is NOT a property of sets?
a) Sets are unordered
b) Sets allow duplicate elements
c) Sets are mutable
d) Sets do not support indexing

5. Which data types can be stored in a Python set?
a) Only integers
b) Only strings
c) Any immutable data type
d) Any data type, including lists


Set Operations

6. What does the .add() method do in a set?
a) Adds multiple elements
b) Adds a single element
c) Adds elements in sorted order
d) Adds an element at a specific index

7. Which operator is used for set union?
a) &
b) |
c) -
d) ^

8. What will be the output of {1, 2, 3} | {3, 4, 5}?
a) {1, 2, 3, 4, 5}
b) {3}
c) {}
d) {1, 2, 3, 3, 4, 5}

9. What is the result of {1, 2, 3} & {2, 3, 4}?
a) {1, 2, 3, 4}
b) {2, 3}
c) {}
d) {1}

10. What is the result of {1, 2, 3} - {2, 3, 4}?
a) {1}
b) {}
c) {2, 3}
d) {4}


Set Methods

  1. What does the .update() method do?
    a) Removes duplicates from a set
    b) Adds multiple elements to a set
    c) Removes an element
    d) Clears the set
  1. Which method is used to remove an element from a set safely (without an error if the element is missing)?
    a) .discard()
    b) .remove()
    c) .delete()
    d) .pop()
  1. What does the .pop() method do in a set?
    a) Removes the last element
    b) Removes the first element
    c) Removes and returns a random element
    d) Clears the set
  1. How do you check if an element exists in a set?
    a) set.find(element)
    b) set[element]
    c) element in set
    d) set.has(element)
  1. What does set.clear() do?
    a) Deletes one element from the set
    b) Deletes the entire set
    c) Removes all elements but keeps the set empty
    d) Returns a new set

Advanced Set Concepts

  1. What is the difference between .remove() and .discard()?
    a) No difference
    b) .remove() raises an error if the element is missing, but .discard() does not
    c) .remove() deletes all occurrences, but .discard() deletes only one
    d) .remove() works on lists, but .discard() works on sets
  1. What does the .symmetric_difference() method do?
    a) Returns the common elements
    b) Returns the elements unique to each set
    c) Removes duplicates from a set
    d) Sorts the set
  1. Which method can be used to check if one set is a subset of another?
    a) .issubset()
    b) .issuperset()
    c) .ispartof()
    d) .subsetof()
  1. What will A = {1, 2, 3}; B = {1, 2, 3, 4, 5}; print(A.issubset(B)) return?
    a) True
    b) False
    c) Error
    d) {1, 2, 3}
  1. What will A = {1, 2, 3, 4, 5}; B = {1, 2, 3}; print(A.issuperset(B)) return?
    a) True
    b) False
    c) Error
    d) {1, 2, 3, 4, 5}

How did you do? 🎯

  • 18-20 correct → 🏆 Excellent! You’re a Python functions pro!
  • 14-17 correct → 👍 Great job! Keep practicing.
  • 10-13 correct → 🙂 Good, but there’s room for improvement.
  • Below 10 → 🤔 No worries! Review the concepts and try again.

by AICorr Team

We are proud to offer our extensive knowledge to you, for free. The AICorr Team puts a lot of effort in researching, testing, and writing the content within the platform (aicorr.com). We hope that you learn and progress forward.