神交python已久,干中学——3数据容器
数据容器:
1.list列表
aa=[], bb=list(),cc = [1,2,3],dd=['1','2','3'],正向0开始,反向-1开始
操作:.append(元素)、.extend(容器)、.insert(下标,元素)、del 列表[下标]、.pop(下标)、.remove(元素)、.clear()、.count()、.index()、len(列表)
2.tuple元组
aa=(),bb=tuple(),cc=(1,2,3),dd=('1','2','3')
操作:index、count、len
不允许修改
3.str字符串
操作:字符串[下标]、.index()、.replace()、.split()、.strip()、.count()、len()
4.序列
list=[1,2,3,4]
new_list = list[1:4]
new_list=list[:]
new_list=list[::2] 步长2
5.set集合
aa={1,2,3},bb=set()
操作:.add()、.remove()、.pop()、.clear()、.difference()、.difference_update()、.union()、len()
数据无序
6.dict(字典、映射)
aa={},bb=dict(),cc={a:1,b:'2'}
操作:字典[key]、.pop(key)、.clear()、.keys()、len()
不支持下标
容器通用:
for循环、max()、min()、len()、list()、tuple()、str()、set()、sorted()