Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson6-4
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
229a1e58
authored
Sep 15, 2020
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
07ef43ed
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
0 deletions
diy.py
diy.py
View file @
229a1e58
...
@@ -3,5 +3,38 @@
...
@@ -3,5 +3,38 @@
# 省略繁杂情节,刘关张三人一起冲入战场,围攻吕布:
# 省略繁杂情节,刘关张三人一起冲入战场,围攻吕布:
a
=
[
'吕布'
]
a
=
[
'吕布'
]
b
=
[
'袁术'
,
'公孙瓒'
,
'关羽'
,
'张飞'
,
'刘备'
,
'曹操'
]
b
=
[
'袁术'
,
'公孙瓒'
,
'关羽'
,
'张飞'
,
'刘备'
,
'曹操'
]
#如果想要从一个列表中获取多个元素,可以使用切片的方法
#切片格式: 列表名[起始位置:终止位置:步长]
#切片遵循取左不取右的原理,终止位置应该是我们想要取到数据的索引+1
#切片如果省略开头,就从列表头部开始
#切片如果省略结尾,就截至到列表的尾部。
#如果在中括号里只写一个冒号,代表是开头到结束
a
.
extend
(
b
[
2
:
5
])
print
(
a
)
1.
列表的创建
列表名
赋值号
[
数据
,
数据
]
例:
name
=
[
"jack"
,
"mick"
,
"milk"
]
2.
列表中数字和字符串可以同时出现
3.
列表可以存放多个数据,功能类似于变量,但是比变量存放的数据多
4.
删除列表中的指定元素可以使用:
pop
()
remove
()
有
3
种
5.
第一种,利用
pop
和从左到右正序数索引,索引从
0
开始
b
.
pop
(
3
)
6.
第二种,利用
remove
方法,删除指定元素,第一次出现的
b
.
remove
(
"关羽"
)
7.
第三种,利用
pop
和从右往左倒序数索引,索引从
-
1
开始
8.
在列表中插入一个数据,可以使用
insert
和
append
10.
insert
是在指定位置插入一个数据,我们可以任意挑选位置,位置是列表的索引
11.
append
是在列表末尾插入一个数据,仅允许插入
1
个
12.
extend
是在列表中插入一个新的列表
13.
在字符串中,单引号和双引号的功能是一样的,都是标识字符串,要成对出现
14.
如果想要从一个列表中获取多个元素,可以使用切片的方法
15.
切片格式:
列表名
[
起始位置
:
终止位置
:
步长
]
16.
切片遵循取左不取右的原理,终止位置应该是我们想要取到数据的索引
+
1
17.
切片如果省略开头,就从列表头部开始
18.
切片如果省略结尾,就截至到列表的尾部。
19.
如果在中括号里只写一个冒号,代表是开头到结束
\ 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