import copy

flowers = ["玫瑰", "百合", "月季", "牡丹", "青囊", "疗愁", "灵芝", "珍珠花", "瑞圣花", "合欢花", "百花"]
flowers.append("曼陀罗") # 尾部插入
flowers.insert(1, "虞美人") # 指定位置插入
flowers[2] = "洛如花" # 改值
print(flowers)

切片

"""print(flowers[0], flowers[2])
print(flowers[1:3]) # 切片 顾头不顾尾
print(flowers[-1]) # 切片
print(flowers[-3: -1]) # 切片
print(flowers[-3:]) # 切片
print(flowers[0:3]) # 切片
print(flowers[:3]) # 切片"""

删除

"""
flowers.remove("月季")
print(flowers)
flowers.pop() # 默认为末位,删除下标位置上的内容
del flowers[0]
print(flowers)
print(flowers.index("灵芝")) # 打印位置
print(flowers[flowers.index("灵芝")]) # 打印所在位置的元素
print(flowers.count("牡丹")) # 打印元素出现的次数
flowers.clear() # 清除列表
"""

"""
flowers.reverse() # 列表内容顺序翻转
print(flowers)
flowers.sort() # 列表内容自动排序
print(flowers)

flowers2 = ["迎辇花", "木香花", "凤仙花", "紫荆花", "蔷薇", "秋牡丹", "锦带花", "玉蕊花", "八仙花", "子午花", "青鸾花", "旌节花", "瑞香花", "荼蘼花", "月季", "夜来香", "罂粟", "石竹花", "蓝菊花", "丁香"]
flowers.extend(flowers2) # 合并
print(flowers)
print(flowers2)

del flowers2 删除变量

"""

"""

复制

mylist = [1, 2, [1, 2, [1, 2, 3]], 3, 4, 5]
"""
"""

引用列表

mylistnew = mylist
mylist[3] = 10000
print(id(mylist), id(mylistnew))
print(mylist)
print(mylistnew)
"""

"""

浅复制

mylistnew = mylist.copy()
print(id(mylistnew), id(mylist))
mylist[2][0] = "10000"
print(mylist)
print(mylistnew)
"""
"""

深复制

mylistnew = copy.deepcopy(mylist) # 深复制
print(id(mylist), id(mylistnew))
mylist[2][2][0] = 10000
print(mylist)
print(mylistnew)
"""

"""
曼陀罗、虞美人、洛如花、青囊、疗愁、灵芝、玫瑰、珍珠花、瑞圣花、合欢花、百花、
牡丹、木笔花、洛阳花、兰花、菊花、琼花、莲花、梅花、海棠花、桂花、杏花、芍药、
茉莉、芙蓉、笑靥花、紫薇花、含笑花、杜鹃、玉兰、蜡梅、水仙、木莲、素馨花、
结香花、铁树花、碧桃花、绣球花、木兰花、秋海棠、刺蘼花、玉簇花、木棉花、凌霄花、
迎辇花、木香花、凤仙花、紫荆花、蔷薇、秋牡丹、锦带花、玉蕊花、八仙花、子午花、
青鸾花、旌节花、瑞香花、荼蘼花、月季、夜来香、罂粟、石竹花、蓝菊花、丁香、
棣棠花、迎春花、千日红、翦春罗花、夹竹桃、牡丹花、西番莲、金丝桃花、翦秋纱花、
十姊妹花、丽春花、山丹花、玉簪花、金雀花、栀子花、真珠兰花、佛桑花、长春花、
山矾花、宝相花、木槿花、蜀葵花、鸡冠花、蝴蝶花、秋葵花、紫菜莉花、梨花、藤花、
芦花、蓼花、葵花、杨花、桃花、苹花、菱花、百合
"""

print(flowers[0👎2])
print(flowers[::2])

for i in flowers:
print(i)

person = ["name", ["a", 100]]

"""
p1 = copy.copy(person)
p2 = person[:]
p3 = list(person)

print(p1)
print(p2)
print(p3)
"""

浅拷贝的应用

模版

两个人的共有账户

p4 = person[:]
p5 = person[:]
print(p4)
print(p5)

p4[0] = "lilei"
p5[0] = "liling"
print(p4)
print(p5)

p4[1][1] = 50
print(p4)
print(p5)