Commit 76464018 by BellCodeEditor

auto save

parent e8ac9a19
Showing with 43 additions and 0 deletions
bros = ['刘备','关羽','张飞']
#位置交换
bros[0],bros[1] = bros[1], bros[0]
print(bros)
print('-'*20)
#列表的遍历 一
for i in range(len(bros)):
print(bros[i])
print('-'*20)
#列表的便利 二
for i in bros:
print(i)
print('-'*20)
#练习删除remove指定元素 ,从左往右只能删除第一个出现的元素
list = ['a','b','c','d','a','r','a']
list.remove('a')
print(list)
list.pop(-1)
print(list)
print('-'*20)
#学习在列表中插入元素 insert ,append
a = ['华雄']
a.insert(1,'关羽') #指定索引添加
print(a)
a.append('张飞') #在列表的末尾添加
print(a)
#在列表的末尾添加一个列表 extend
c=['颜良','文丑']
a.extend(c) #在列表的末尾添加列表
print(a)
print('-'*20)
#切片 取左不取右 不写全都取
b = ['张飞','吕布','赵云','夏侯惇','曹操','公孙瓒']
#取出'赵云','夏侯惇','曹操
print(b[2:-1])
#取出吕布到公孙瓒
print(b[1:])
#全都取
print(b[:])
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment