Commit d6ec7f78 by BellCodeEditor

auto save

parent 5265ca6b
Showing with 24 additions and 2 deletions
...@@ -3,4 +3,27 @@ ...@@ -3,4 +3,27 @@
# 和你的小伙伴用列表讲讲温酒斩华雄的故事,上半集,并完成下面的挑战: # 和你的小伙伴用列表讲讲温酒斩华雄的故事,上半集,并完成下面的挑战:
#这时还是无名小卒的关羽上前请战,请从b列表中删掉“关羽”,用三种方法哦。 #这时还是无名小卒的关羽上前请战,请从b列表中删掉“关羽”,用三种方法哦。
b=['袁术','夏侯惇','曹操','关羽'] b=['袁术','夏侯惇','曹操','关羽']
\ No newline at end of file #让关二爷出战,从盟军的列表中删除关二爷
#删除列表中的指定元素可以使用:pop() remove() 有3种
#第一种,利用pop和从左到右正序数索引,索引从0开始
#b.pop(3)
#第二种,利用remove方法,删除指定元素,第一次出现的
#b.remove("关羽")
#第三种,利用pop和从右往左倒序数索引,索引从-1开始
b.pop(-1)
print(b)
a = ['华雄']
#在列表中插入一个数据,可以使用insert和append
#insert是在指定位置插入一个数据,我们可以任意挑选位置,位置是列表的索引
#append是在列表末尾插入一个数据,仅允许插入1个
#extend是在列表中插入一个新的列表
#在字符串中,单引号和双引号的功能是一样的,都是标识字符串,要成对出现
a.insert(1,"关羽")
a.append("关羽")
c = ['颜良','文丑']
a.extend(c)
print(a)
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