name ="ocean" age=16 job="soft" msg2=''' -------info of %s----- Name: %s Age: %s Job: %s -------end--------- '''%(name,name,age,job) 查 索引(下标) ,都是从0开始 切片 .count 查某个元素的出现次数 .index 根据内容找其对应的位置 "haidilao ge" in a 增加 a.append() 追加 a.insert(index, "内容") a.extend 扩展 修改 a[index] = "新的值" a[start:end] = [a,b,c] 删除 remove("内容") pop(index) del a, del a[index] a.clear() 清空 排序 sort () reverse() 身份判断 >>> type(a) is list
True >>>a=['1','2']#b=a相当于地址传递,a改变,b也会改变,b改变列表值,a也会改变b=a[0]#值传递,a在改变值,b获取的值不变
s = [[1,2],'alex','alvin']
s3=s.copy()
s3[1]='ocean'
s3[0][1]=3
print(s)
print(s3)
############下面是输出
[[1, 3], 'alex', 'alvin']
[[1, 3], 'ocean', 'alvin']#就算用copy命令,列表里的列表会被改变,列表里的其他没变化