python内置数据结构

时间:2019-05-28 15:09:34   收藏:0   阅读:117

数据类型:

数值型

序列对象

键值对

数值型:

类型转换:

数字处理函数:

import math
#向下取值,地板
print(math.floor(2.5),math.floor(-2.5)) 
#向上取值,天花板
print(math.ceil(2.5), math.ceil(-2.5))  
#测试四舍六入五取偶
print(round(3.5), round(3.5001), round(3.6), round(3.3))
#判断类型,但会一个bool值
print(isinstance(6, str))
print(isinstance(6, (str, bool, int)))

类型判断

 

序列对象

列表(list)

 列表list定义

lst = list()
lst = []
lst = [2,6,9,ab]
lst = list(range(5))

列表索引访问

 列表查询

index(value,[start,[stop]])

count(value)

时间复杂度

如何返回列表元素的个数?如果遍历?如何设计高效?

列表元素修改

索引访问修改

l = [1,2,3,4,5]
l[3] = "jaxzhai"
l

列表增加、插入元素

append(object) ->None

insert(index,object) -> None

extend(iteratable) -> None

+ -> list

* -> list

列表删除元素

remove(value) -> None

pop([index]) -> item

clear() -> None

列表其它操作

reverse() -> None

sort(key=None,reverse=False) -> None

in

列表复制

lst0 = list(range(4)) 
lst2 = list(range(4)) 
print(lst0==lst2) 
lst1 = lst0
lst1[2] = 10 
print(lst0)

copy() -> list

浅拷贝

技术分享图片

深拷贝

技术分享图片

 

import copy
lst0 = [1, [2, 3, 4], 5]
lst5 = copy.deepcopy(lst0)
lst5[1][1] = 20
lst5 == lst0


这个执行结果就是False

 随机数

random模块

原文:https://www.cnblogs.com/xzkzzz/p/10863095.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!