Terms

1 new/unreviewed 1 total

Term

列表是什么 使用列表中的值 修改列表元素 添加

Definition

特点: 有序(有先后顺序) 可修改(能增删改) 能装任意类型数据 列表里的每个元素都有编号(索引),从 0 开始数。 格式:列表名[索引] python 运行 fruits = ["苹果", "香蕉", "橙子", "西瓜"] # 取第1个元素 print(fruits[0]) # 苹果 --------------------------------------------------------------------------------- fruits = ["苹果", "香蕉", "橙子"] # 把第2个元素改成"葡萄" fruits[1] = "葡萄" print(fruits) # ['苹果', '葡萄', '橙子'] -------------------------------------------------------------------------------------- fruits = ["苹果", "香蕉"] # 在最后加一个"梨" fruits.append("梨") print(fruits) # ['苹果', '香蕉', '梨'] 方法 2:指定位置插入 → insert (索引,值) 运行 fruits = ["苹果", "香蕉"] # 在第2个位置插入"草莓" fruits.insert(1, "草莓") print(fruits) # ['苹果', '草莓', '香蕉']

New/Unreviewed

Practice Tests

0 total
(None) Completed practice tests will show up here