Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson6-2
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d6ec7f78
authored
Sep 15, 2020
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
5265ca6b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
2 deletions
diy.py
diy.py
View file @
d6ec7f78
...
@@ -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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment