Published on

[Python 學習筆記] 6-容器型別

Authors
  • avatar
    Name
    Vic Chen
    Twitter

容器型別(Data Structures)

Python 提供了四種常用的容器型別,每種都有不同的特性與適用場景:

型別說明可變性範例
list有序可重複可變[1, 2, 3]
tuple有序不可變不可變(1, 2, 3)
set無序唯一可變{1, 2, 3}
dict鍵值對可變{'a': 1, 'b': 2}

Quick overview

# List
fruits = ["apple", "banana", "cherry"]

# Tuple
point = (10, 20)

# Set
unique_numbers = {1, 2, 3}

# Dict
person = {"name": "Alice", "age": 25}

學習導覽

  1. List(列表)
  2. Tuple(元組)
  3. Set(集合)
  4. Dict(字典)