1.列表里可以存放什么东西?
可以存放任何的数据类型,
list1 = ['我爱你','i love you',1314]
print(list1)
2.向列表中添加元素
append(将参数作为一个元素添加到列表的结尾)
list1 = ['我爱你','i love you',1314]
print(list1)
list1.append(['forever','just you'])
print(list1)
extend (将参数作为一个列表添加到列表的结尾)
list1 = ['我爱你','i love you','']print(list1)
list1.extend(['forever','just you'])
print(list1)
insert(将参数插入到列表)
list1 = ['我爱你','i love you','']
print(list1)
list1.insert(3,'forever')
print(list1)
3
list3 = ['小甲鱼',88,'黑夜',90,'迷途',85,'怡静',90,'秋舞斜阳',88]
for each in list3:
print(each)
4(不会,看小甲鱼的)
list3 = ['小甲鱼',88,'黑夜',90,'迷途',85,'怡静',90,'秋舞斜阳',88]
count = 0
length = len(list3)
while count < length:
print(list3[count],list3[count+1])
count += 2
list3 = ['小甲鱼',88,'黑夜',90,'迷途',85,'怡静',90,'秋舞斜阳',88]
for each in range(len(list3)):
if each%2 == 0:
print(list3[each],list3[each+1])