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...