append与insert定义

# 写法:列表名.append(数据)
# 定义:往列表的最后位置添加数据
ac = ['茶叶','香烟','杯子','开水']
# print(ac.append('打火机')) #print只做添加,不出结果,返回None(空)
ac.append('打火机')
print(ac)
# 写法:列表名.insert(编号,数据)
# 指定位置添加数据
ac.insert(0,'手机架')
print(ac)
posted @ 2023-12-25 10:29  罗科-ROCCO  阅读(3)  评论(0编辑  收藏  举报