Python 串列

Python 入門

Hugo Bowne-Anderson

Data Scientist at DataCamp

Python 資料型別

  • float - 實數

  • int - 整數

  • str - 字串、文字

  • bool - True、False

height = 1.73
tall = True
  • 每個變數都表示單獨的值
Python 入門

問題

  • 資料科學:大量資料點

  • 全家人的身高資料

height1 = 1.73
height2 = 1.68
height3 = 1.71
height4 = 1.89
  • 不方便
Python 入門

Python 串列

  • [a, b, c]
[1.73, 1.68, 1.71, 1.89]
[1.73, 1.68, 1.71, 1.89]
fam = [1.73, 1.68, 1.71, 1.89]
fam
[1.73, 1.68, 1.71, 1.89]
  • 為數值集合命名

  • 包含任意類型

  • 包含不同類型

Python 入門

Python 串列

  • [a, b, c]
fam = ["liz", 1.73, "emma", 1.68, "mom", 1.71, "dad", 1.89]

fam
['liz', 1.73, 'emma', 1.68, 'mom', 1.71, 'dad', 1.89]
fam2 = [["liz", 1.73],
        ["emma", 1.68],
        ["mom", 1.71],
        ["dad", 1.89]]

fam2
[['liz', 1.73], ['emma', 1.68], ['mom', 1.71], ['dad', 1.89]]
Python 入門

串列型別

type(fam)
list
type(fam2)
list
  • 特定功能

  • 特定行為

Python 入門

一起來練習吧!

Python 入門

Preparing Video For Download...