Skip to content
Worked Examples · Example 5.6

Q.Example 5.6:
#create a set
set1 = {10,20,3.14,"New Delhi"}
print(type(set1))
<class 'set'>
print(set1)
{10, 20, 3.14, "New Delhi"}
#duplicate elements are not included in set
set2 = {1,2,1,3}
print(set2)
{1, 2, 3}

West Bengal WbchseTextbookSubjective· 2mImportance★★★★★est
22% · 11/49 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Sets, written in curly braces, are unordered collections with no duplicates — type(set1) is <class 'set'>, the print order is arbitrary, and {1, 2, 1, 3} collapses to {1, 2, 3}.

The concept is the set data type, defined by two properties: elements are unique (a duplicate simply is not stored twice) and unordered (a set has no positions — you cannot index set1[0]).

#create a set
>>> set1 = {10, 20, 3.14, "New Delhi"}
>>> print(type(set1))
<class 'set'>
>>> print(set1)
{10, 20, 3.14, 'New Delhi'}
#duplicate elements are not included in set
>>> set2 = {1, 2, 1, 3}
>>> print(set2)
{1, 2, 3}

Walking through:

  • set1 = {10, 20, 3.14, "New Delhi"} — curly braces (without key:value pairs) create a set; mixed types are fine as long as elements are immutable.
  • print(type(set1)) → <class 'set'>.
  • print(set1) — the elements appear in whatever order the set's internal hashing produces, not insertion order. Your run may well print {'New Delhi', 10, 3.14, 20} — equally correct. Python also displays the string in single quotes ('New Delhi'), though the book's answer shows double quotes. …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.