2022.06.07学习内容
Python
English
Python
1.掌握列表的常用方法
使用中括号定义[值1,值2,值3]
列表常用方法
增
insert(索引,数据)
指定索引处插入数据
append(数据)
末尾追加数据
extend(列表)
追加另一个列表,或者元组的值
删
del(列表[索引])
remove(数据),删除第一次出现的指定数据
pop()删除末尾数据
pop(索引)删除指定索引的数据
clear()清空列表
改
list[index]=值
查
list[index]
count(数据),返回指定数据在列表出现的次数
index(数据),返回数据的索引值
排序
sort()
sort(reverse=True)
reverse()反转
dir()查看某类型中定义的方法
dir(list1),查看列表list1中的所有方法
2.使用for循环遍历列表
拆包,把列表,元素中的值拆出来:
变量1,变量2,变量n=列表/元组
Python不写成list[index]
列表推导式:
轻量级地循环创建列表
list=[x for x in range(1,10)]
list=[x for x in range(20) if x%2]
for item in list
3.掌握公共方法的使用:
len(list/tuple)
max(list/tuple)
min(list/tuple)
值 in list/tuple
值 not in list/tuple
4.了解元组和列表的不同
元组理解为只读的列表
tuple=(值1,)
tuple=值1,
tuple=值1,值2
tuple=(值1,值2)
列表、元组的转换
列表转换为元组就是为了让列表不可以被修改,保护数据;元组转换为列表就是为了修改数据
list1=list(tuple)
tuple1=tuple(list1)
English Word
handbag 手提包
grape 葡萄
something 某些事物
blog 博客
already 已经
any 任何的
lend 借
she 她
supermarket 超市
hip-hop 嘻哈