list # 类,列表
li = [1,12,9,"age",["石振文", ["19",1], "庞麦郎"], "alex"] 通过list类创建的对象,li
#1、列表格式(中括号括起来,分割每个元素)
#2、列表中可以嵌套作任何东西(列表中的元素可是 数字,字符串,列表,布尔值..所有的都能放进去)
#3、索引取值
#4、切片,切片结果也是列表
#5、for循环
#while循环
li = [1,12,9,"age",["石振文",["19",10],"庞麦郎"],"alex",True]
print(li[3])
print(li[3:5])
for item in li:
print(item)
#6、索引
li = [1,12,9,"age",["石振文",["19",10],"庞麦郎"],"alex",True]
#修改
li[1] = 120
print(li)
li[1] = [11,22,33,44]
print(li)
li = [1,12,9,"age",["石振文",["19",10],"庞麦郎"],"alex",True]
#删除,第一种方式
del li[1]
print(li)
#7、切片
li = [1,12,9,"age",["石振文",["19",10],"庞麦郎"],"alex",True]
#修改
li[1:3] = [120,90]
print(li)
li = [1,12,9,"age",["石振文",["19",10],"庞麦郎"],"alex",True]
#删除
del li [2:6]
print(li)
#8、in 操作
li = [1,12,9,"age",["石振文",["19",10],"庞麦郎"],"alex",True]
v = 12 in li
print(v)
v = 120 in li
print(v)
原文:https://www.cnblogs.com/jiangdali/p/10409390.html