Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
lesson14_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
e2e3ec4e
authored
Mar 19, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
e35a8be4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
135 additions
and
2 deletions
总和复习.py
总结复习.py
总和复习.py
deleted
100644 → 0
View file @
e35a8be4
总结复习.py
0 → 100644
View file @
e2e3ec4e
#列表
#列表
l
=
[
1
,
2
,
3
,
4
,
5
]
'''
#列表的增添 extend append insert +
l2 = [6,7]
#一次性添加多个元素
l.extend(l2)
#末尾添加
l.append(8)
#在具体位置添加元素
l.insert(2,9)
#列表的删除pop del clear
l.pop(-1)
#默认删除最后一个
l.pop()
#删除具体元素
del l[0]
#把整个列表都删除
del l
#清空
l.clear()
#删除具体的元素
l.remove(3)
#查找 列表名[索引值]
#索引值:正索引、负索引
#修改 列表名[索引值]=值
#切片 取左不取右 不写全都取 [开始(默认0开始):结束:步长(默认为1)]
l = [1,2,3,4,5,[6,7],"8",9]
print(l[:6])
print(l[2:6])
print(l[4:])
print(l[:4:2])
print(l[:4:-1])
print(l[4:0:-1])
print(l[:])
'''
'''
#遍历 for 只针对于知道次数的序列
#直接遍历可迭代的对象
#range() #只针对整数int 参数特点range(开始,结束,步长) 取左不取右
# for i in l:
# print(i)
# for i in range(len(l)):
# print(l[i])
for i in range(1,5,2):
print(i)
'''
#字符串 索引 查
s
=
'1,2,34,56'
'''
# for i in s:
# print(i)
print(type(s[0]))
#切片:和列表一样
print(s[8:])
#分割 返回列表
a =s.split(",",1)
print(a)
#拼接 "".join()
b = ",,,,,,,,,,,,,".join(a)
print(b)
#字典 的增删改查 字典名[键]
#字典无序
d = {"张三":32,"李四":68,"王五":99}
#增添 键是否已经存在(不存在)
d["刘能'"]=45
#修改 键是否已经存在(不存在)
d["李四"] ="赵四"
#删除 del pop clear
d.pop("李四")
del d["王五"]
del d
#清空
d.clear()
print(d)
d = {"张三":32,"李四":68,"王五":99}
#获取键
d.keys()
#获取值
d.values()
#获取键和值
for i,v in d.items():
print(i,v)
'''
#元组定义
# t = (1,2,3)
# print(type(t))
t
=
(
1
,)
print
(
type
(
t
))
#for 循环
#条件判断 单条件分支if 双条件分支if...else 多条件分支if..elif...else
#while条件判断 关键字break 跳出当前循环 continue 提前进入下一次循环
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