Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson6-1
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
76464018
authored
Jul 24, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
e8ac9a19
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
0 deletions
demo.py
demo.py
0 → 100644
View file @
76464018
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
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