首页 » 开发 » python » 秦路天善智能python学习笔记1-数据类型,常量,变量,列表,字典,元组

秦路天善智能python学习笔记1-数据类型,常量,变量,列表,字典,元组

 

数据类型:弱类型
int
float
str
bool
NoneType
list
tuple
dict
变量,常量
变量定义:a = 1 等号右边先计算 a = a + 1 a=2

数据结构:列表(list),字典,元祖
列表空间节省,查询速度慢
insert(第几位,在第几位之前插入的量)
append(要在最后一位插入的值)
pop(删除第几位)默认是删除最后一个
list = [1,2,3]
list insert(1,4)
[1,4,2,3]
list insert(4,5)
[1,4,2,3,5]
list append(6)
[1,4,2,3,6]
list = list+[7,8,9]
[1,4,2,3,6,7,8,9]
list pop(1)
[1,2,3,5,6,7,8]
list[1] = 4
[1,4,3,5,6,7,8]

列表进阶
a = [1,2,3]
b = [[1,2],[3,4]]
name = ['qinlu','panda','dada']
sex = ['nv','nan','nv']
age = [18,18,20]
info = [name,sex,age]
info = [['qinlu','panda','dada'],['nv','nan','nv'],[name,sex,age]]
info = [1]
['nv','nan','nv']
row = [0]*3
[0,0,0]
[row]*4
[[0,0,0],[0,0,0],[0,0,0],[0,0,0]]

元组:不能修改
a = (1,2)
a[0]
1

字典:查找快,空间占用大
a = {"id":1,"name":"haha","sex":nv,"age":18}
a["id"]
1
"id" in a
True

原文链接:秦路天善智能python学习笔记1-数据类型,常量,变量,列表,字典,元组,转载请注明来源!

0