Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
檀越@新空间
python-demo
提交
66027e26
P
python-demo
项目概览
檀越@新空间
/
python-demo
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
python-demo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
66027e26
编写于
6月 02, 2023
作者:
檀越@新空间
🐭
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:切片
上级
4ec9a916
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
27 addition
and
15 deletion
+27
-15
05_数据容器/02_list列表的常用操作.py
05_数据容器/02_list列表的常用操作.py
+8
-0
05_数据容器/04_list列表的循环.py
05_数据容器/04_list列表的循环.py
+10
-2
05_数据容器/06_字符串.py
05_数据容器/06_字符串.py
+6
-0
05_数据容器/08_序列和切片.py
05_数据容器/08_序列和切片.py
+3
-13
未找到文件。
05_数据容器/02_list列表的常用操作.py
浏览文件 @
66027e26
...
@@ -51,7 +51,15 @@ count = len(mylist)
...
@@ -51,7 +51,15 @@ count = len(mylist)
print
(
f
"列表的元素数量总共有:
{
count
}
个"
)
print
(
f
"列表的元素数量总共有:
{
count
}
个"
)
# 7. 删除某元素在列表中的第一个匹配项
mylist
=
[
"itcast"
,
"itheima"
,
"itcast"
,
"itheima"
,
"python"
]
mylist
.
reverse
()
print
(
f
"通过reverse方法翻转后,列表的结果是:
{
mylist
}
"
)
# 7. 删除某元素在列表中的第一个匹配项
mylist
=
[
"itcast"
,
"itheima"
,
"itcast"
,
"itheima"
,
"python"
]
mylist
.
remove
(
"itheima"
)
print
(
f
"通过remove方法移除元素后,列表的结果是:
{
mylist
}
"
)
05_数据容器/04_list列表的循环.py
浏览文件 @
66027e26
...
@@ -11,13 +11,21 @@ def list_while_func():
...
@@ -11,13 +11,21 @@ def list_while_func():
mylist
=
[
"传智教育"
,
"黑马程序员"
,
"Python"
]
mylist
=
[
"传智教育"
,
"黑马程序员"
,
"Python"
]
# 循环控制变量:通过下标索引来控制,默认0
# 循环控制变量:通过下标索引来控制,默认0
# 每一次循环将下标苏姚
# 每一次循环将下标苏姚
index
=
0
while
index
<
len
(
mylist
):
print
(
mylist
[
index
])
index
+=
1
# list_while_func()
def
list_for_func
():
def
list_for_func
():
"""
"""
使用for循环遍历列表的演示函数
使用for循环遍历列表的演示函数
:return:
:return:
"""
"""
mylist
=
[
"传智教育"
,
"黑马程序员"
,
"Python"
]
for
e
in
mylist
:
print
(
e
)
list_for_func
()
05_数据容器/06_字符串.py
浏览文件 @
66027e26
...
@@ -38,3 +38,8 @@ print(f"字符串{my_str}中it出现的次数是:{count}")
...
@@ -38,3 +38,8 @@ print(f"字符串{my_str}中it出现的次数是:{count}")
# 统计字符串的长度, len()
# 统计字符串的长度, len()
num
=
len
(
my_str
)
num
=
len
(
my_str
)
print
(
f
"字符串
{
my_str
}
的长度是:
{
num
}
"
)
print
(
f
"字符串
{
my_str
}
的长度是:
{
num
}
"
)
my_str
=
"12itheima and itcast21"
new_my_str
=
my_str
.
strip
(
"231"
)
print
(
f
"字符串
{
my_str
}
被strip('12')后,结果:
{
new_my_str
}
"
)
\ No newline at end of file
05_数据容器/08_序列和切片.py
浏览文件 @
66027e26
"""
"""
演示对序列进行切片操作
演示对序列进行切片操作
"""
"""
# 对list进行切片,从1开始,4结束,步长1
# 对list进行切片,从1开始,4结束,步长1
my_list
=
[
0
,
1
,
2
,
3
,
4
,
5
,
6
]
my_list
=
[
0
,
1
,
2
,
3
,
4
,
5
,
6
]
result1
=
my_list
[
1
:
4
]
# 步长默认是1,所以可以省略不写
result1
=
my_list
[
1
:
4
]
# 步长默认是1,所以可以省略不写
print
(
f
"结果1:
{
result1
}
"
)
print
(
f
"结果1:
{
result1
}
"
)
# 对tuple进行切片,从头开始,到最后结束,步长1
# 对tuple进行切片,从头开始,到最后结束,步长1
my_tuple
=
(
0
,
1
,
2
,
3
,
4
,
5
,
6
)
my_tuple
=
(
0
,
1
,
2
,
3
,
4
,
5
,
6
)
result2
=
my_tuple
[:]
# 起始和结束不写表示从头到尾,步长为1可以省略
result2
=
my_tuple
[:]
# 起始和结束不写表示从头到尾,步长为1可以省略
print
(
f
"结果2:
{
result2
}
"
)
print
(
f
"结果2:
{
result2
}
"
)
# 对str进行切片,从头开始,到最后结束,步长2
# 对str进行切片,从头开始,到最后结束,步长2
my_str
=
"01234567"
my_str
=
"01234567"
result3
=
my_str
[::
2
]
result3
=
my_str
[::
2
]
print
(
f
"结果3:
{
result3
}
"
)
print
(
f
"结果3:
{
result3
}
"
)
# 对str进行切片,从头开始,到最后结束,步长-1
# 对str进行切片,从头开始,到最后结束,步长-1
my_str
=
"01234567"
my_str
=
"01234567"
result4
=
my_str
[::
-
1
]
# 等同于将序列反转了
result4
=
my_str
[::
-
1
]
# 等同于将序列反转了
print
(
f
"结果4:
{
result4
}
"
)
print
(
f
"结果4:
{
result4
}
"
)
# 对列表进行切片,从3开始,到1结束,步长-1
# 对列表进行切片,从3开始,到1结束,步长-1
my_list
=
[
0
,
1
,
2
,
3
,
4
,
5
,
6
]
my_list
=
[
0
,
1
,
2
,
3
,
4
,
5
,
6
]
result5
=
my_list
[
3
:
1
:
-
1
]
result5
=
my_list
[
3
:
1
:
-
1
]
print
(
f
"结果5:
{
result5
}
"
)
print
(
f
"结果5:
{
result5
}
"
)
# 对元组进行切片,从头开始,到尾结束,步长-2
# 对元组进行切片,从头开始,到尾结束,步长-2
my_tuple
=
(
0
,
1
,
2
,
3
,
4
,
5
,
6
)
my_tuple
=
(
0
,
1
,
2
,
3
,
4
,
5
,
6
)
result6
=
my_tuple
[::
-
2
]
result6
=
my_tuple
[::
-
2
]
print
(
f
"结果6:
{
result6
}
"
)
print
(
f
"结果6:
{
result6
}
"
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录