Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson6-5-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
6e40b1f0
authored
Sep 15, 2020
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
d84e0f6c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
8 deletions
diy.py
diy.py
View file @
6e40b1f0
# 臂力挑战赛
1.
列表的创建
列表名
赋值号
[
数据
,
数据
]
例:
name
=
[
"jack"
,
"mick"
,
"milk"
]
# 快用你机灵的小脑瓜想想,如何将刘强和他的臂力值自动插入到hero列表中?
2.
列表中数字和字符串可以同时出现
name
=
'刘强'
3.
列表可以存放多个数据,功能类似于变量,但是比变量存放的数据多
power
=
66
hero
=
[
'赵一'
,
30
,
'丁二'
,
37
,
'孙五'
,
52
,
'王猛'
,
89
,
'周亮'
,
98
]
# 自动排序
删除列表中的指定元素可以使用:
pop
()
remove
()
有
3
种
第一种,利用
pop
和从左到右正序数索引,索引从
0
开始
b
.
pop
(
3
)
第二种,利用
remove
方法,删除指定元素,第一次出现的
b
.
remove
(
"关羽"
)
第三种,利用
pop
和从右往左倒序数索引,索引从
-
1
开始
print
(
hero
)
\ No newline at end of file
在列表中插入一个数据,可以使用
insert
和
append
insert
是在指定位置插入一个数据,我们可以任意挑选位置,位置是列表的索引
append
是在列表末尾插入一个数据,仅允许插入
1
个
extend
是在列表中插入一个新的列表
在字符串中,单引号和双引号的功能是一样的,都是标识字符串,要成对出现
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