现实世界中总存在一组一组的事物,
一、列表的定义
type(['hello','world',1,9,True,False]) = <class 'list'>
type([[1,2,3,],[1,2],[True,False]]) =<class 'list'> 嵌套列表
二、列表的基本操作
['第一个数','第二个数','第三个数','第四个数'][-1]='第四个数'
['第一个数','第二个数','第三个数','第四个数'][-2:]=['第三个数', '第四个数']
['第一个数','第二个数','第三个数','第四个数']+['另外一个数','另外第二个数']=['第一个数', '第二个数', '第三个数', '第四个数', '另外一个数', '另外第二个数']
['第一个数','第二个数','第三个数','第四个数']*3=['第一个数', '第二个数', '第三个数', '第四个数', '第一个数', '第二个数', '第三个数', '第四个数', '第一个数', '第二个数', '第三个数', '第四个数']
表示世界杯分组情况 [['巴西','克罗地亚','墨西哥','喀麦隆'],[],[],[],[],[],[],[]]
三、元组
(1, 2, 3, 4, 5)
(1, -1, True)
(1,2,3,4,5)[2]=3
(1,2,3,4,5)[:2]=(1, 2)
(1,2,3,4,5)+(6,7)=(1, 2, 3, 4, 5, 6, 7)
(1,2,3,4,5)*3=(1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5)、
type((1,2,3))=<class 'tuple'>
type((1))=<class 'int'> type((1,))=<class 'tuple'> type(())=<class 'tuple'>
type(("hello"))=<class 'str'> ()括号 定义运算 所以当括号只有一个元素时候 括号当作是运算符号 而不是元祖的标识
四、序列总结
有序
int, float, bool, str, list, tuple
str, list, tuple 序列
共有操作
每个序列元素都有一个序号
切片 ['第一个数','第二个数','第三个数','第四个数'][-2:]=['第三个数', '第四个数']
是否包含元素 3 in [1,2,3,4,5,6] =True 3 not in [1,2,3,4,5,6]=False
+ * 操作
len([1,2,3,4,5,6])=6 len("hello world")=11
max([1,2,3,4,5,6])=6 min([1,2,3,4,5,6])=1 max("hello world")=“w”
ord() 接受一个参数 转换成为ascll 码 ord("w")=119 ord(" ")=32
五、set 集合 {}
无序,不支持序列操作
type({1,2,3,4,5,6})=<class 'set'>
不重复性 {1,1,2,2,3,3,4,4}={1, 2, 3, 4}
len({1,2,3,4,5,6})=6
3 in {1,2,3,4,5,6}=True
3 not in {1,2,3,4,5,6}=False
求两个集合差集 {1,2,3,4,5,6} - {3,4} = {1, 2, 5, 6}
求两个集合的交集 {1,2,3,4,5,6} & {3,4} = {3, 4}
求两个集合的合集 {1,2,3,4,5,6} | {3,4,7} = {1, 2, 3, 4, 5, 6, 7}
如何定义空的集合 set()
六、dict 字典
Key Value
字典定义形式{}
七、 思维导图总结基本数据类型