python学习-16 列表list
2020-12-13 03:57
标签:lov finish 中括号 索引 判断 lis ini 取值 python学习 1.由[ ]括住,中括号内各元素由逗号隔开,各元素可以是数字,字符串,列表,布尔值等等。 例如: ps:列表是可以嵌套的 2.取值 -索引取值: 输出结果: -切片取值: 输出结果: -循环 输出结果: 2.列表元素是可以修改的 运行结果: 也可以通过切片的方式修改: 运行结果: 2.列表元素的删除 第一种方法: 运行结果: 3.判断是否在列表里(嵌套的元素是一个整体) 运行结果: python学习-16 列表list 标签:lov finish 中括号 索引 判断 lis ini 取值 python学习 原文地址:https://www.cnblogs.com/liujinjing521/p/11098894.htmllist
li = [521,"love",["john","boy",12],True]
print(li)li = [123,"love",[‘a‘,132,‘abc‘],"我爱你",True]
print(li[3])
我爱你
Process finished with exit code 0
li = [123,"love",[‘a‘,132,‘abc‘],"我爱你",True]
print(li[1:5])
[‘love‘, [‘a‘, 132, ‘abc‘], ‘我爱你‘, True]
Process finished with exit code 0
li = [123,"love",[‘a‘,132,‘abc‘],"我爱你",True]
for a in li :
print(a)
123
love
[‘a‘, 132, ‘abc‘]
我爱你
True
Process finished with exit code 0
li = [123,"love",[‘a‘,132,‘abc‘],"我爱你",True]
li[0] = ‘cao‘
print(li)
[‘cao‘, ‘love‘, [‘a‘, 132, ‘abc‘], ‘我爱你‘, True]
Process finished with exit code 0
li = [123,"love",[‘a‘,132,‘abc‘],"我爱你",True]
li[0:3] = [‘cao‘,‘ni‘,‘ma‘]
print(li)
[‘cao‘, ‘ni‘, ‘ma‘, ‘我爱你‘, True]
Process finished with exit code 0
li = [123,"love",[‘a‘,132,‘abc‘],"我爱你",True]
del li[0]
print(li)
[‘love‘, [‘a‘, 132, ‘abc‘], ‘我爱你‘, True]
Process finished with exit code 0
li = [123,"love",[‘a‘,132,‘abc‘],"我爱你",True]
a = "abc" in li
print(a)
False
Process finished with exit code 0