Sets in python: 18 MCQs

All 18 multiple-choice questions from this kit, free and with no sign-up.

Warm-up · 8 questions

Q1. What is the correct way to create an empty set in Python?

Beginner
A {}
B ()
C []
D set()

Answers and explanations are in the Veda app.

Q2. Which of the following is a property of a Python set?

Beginner
A Mutable
B Ordered
C Allows duplicates
D Indexable

Answers and explanations are in the Veda app.

Q3. Which method adds an element to a set?

Beginner
A insert()
B append()
C extend()
D add()

Answers and explanations are in the Veda app.

Q4. What is the output of `len({1, 2, 3, 2, 1})`?

Beginner
A 2
B Error
C 3
D 5

Answers and explanations are in the Veda app.

Q5. A set can contain duplicate elements.

Beginner
A True
B False

Answers and explanations are in the Veda app.

Q6. You can access elements of a set using an index like `my_set[0]`.

Beginner
A True
B False

Answers and explanations are in the Veda app.

Q7. The `clear()` method removes all elements from a set.

Beginner
A True
B False

Answers and explanations are in the Veda app.

Q8. A set can contain both integers and strings.

Beginner
A True
B False

Answers and explanations are in the Veda app.

Building up · 9 questions

Q9. What will be the output of `{1, 2, 3} | {2, 3, 4}`?

Intermediate
A {1, 2, 3, 4}
B Error
C {2, 3}
D {1, 4}

Answers and explanations are in the Veda app.

Q10. What does `{1, 2, 3} - {2, 3, 4}` return?

Intermediate
A {1}
B {1, 4}
C {2, 3}
D {4}

Answers and explanations are in the Veda app.

Q11. Which of the following cannot be an element of a set?

Intermediate
A Tuple
B Integer
C List
D String

Answers and explanations are in the Veda app.

Q12. Which operator checks if a set is a subset of another?

Intermediate
A <
B <=
C >=
D ==

Answers and explanations are in the Veda app.

Q13. What does `{1, 2, 3} & {2, 3, 4}` return?

Intermediate
A {1, 4}
B {1, 2, 3, 4}
C {2, 3}
D Error

Answers and explanations are in the Veda app.

Q14. Which method removes an element from a set and raises an error if not found?

Intermediate
A delete()
B discard()
C remove()
D pop()

Answers and explanations are in the Veda app.

Q15. What is the output of `{x**2 for x in range(3)}`?

Intermediate
A {0, 1, 2}
B {0, 1, 4}
C Error
D {0, 1, 4, 9}

Answers and explanations are in the Veda app.

Q16. What does `{1, 2}.issuperset({1})` return?

Intermediate
A None
B True
C False
D Error

Answers and explanations are in the Veda app.

Q17. The `^` operator performs symmetric difference on sets.

Intermediate
A True
B False

Answers and explanations are in the Veda app.

Topper level · 1 questions

Q18. Which of the following is true about frozenset?

Advanced
A It is mutable
B It allows duplicates
C It is ordered
D It can be used as a dictionary key

Answers and explanations are in the Veda app.

Make your own

Your notes can be a kit like these

Every kit here was made from real study material. Point Veda at a chapter, a PDF, a photo or a link and get notes, flashcards, practice MCQs, games and a scored test — free to start, in more than 40 languages.

  • Chapter notes
  • Flashcards
  • Practice MCQs
  • Scored tests
  • Paper Solver

Get Veda free See what students get

Free to start · Android app and web · More than 40 languages