搜尋此網誌

2026年6月17日星期三

Set

numbers = set([1, 2, 2, 3])

Square brackets [] in above example are just creating a list before converting it into a set.

Role of Square Brackets
  • [1, 2, 2, 3] → this is a list literal in Python.

  • Lists can contain duplicates and preserve order.

  • Then set([...]) takes that list and removes duplicates, giving {1, 2, 3}.

So the square brackets are not part of the set itself — they’re simply defining the list that you pass into set().

Microsoft Copilot

沒有留言:

發佈留言