Python深度学习 序列

1.python 内置了两种序列结构

容器类型:list,tuple, collections.deque

扁平类型:str, bytes, bytearray,

区别 : 容器类型存储的是对象的引用,而扁平类型存放的是值。

2.列表推到式

一般的情况下,列表推导式一般用于创建列表,可以对列表进行加工并重新创建一个列表。

numbers = [i for i in range(10)]
print(numbers)

结果:
C:\python35\python.exe E:/pytest/pytest8.5.py
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Process finished with exit code 0

补充:在使用list.sort方法时,我们可以进行排序,但是这个排序是在其原来的对象上进行排序的。
sorted()则会创建一个新的对象进行排序。

3.元组拆包

可以使用_作为占位符

import os
_,log_name = os.path.split("/var/openstack/nova.log")    #_作为占位符使用
print(log_name)

C:\python35\python.exe E:/pytest/pytest8.5.py
nova.log

Process finished with exit code 0

4.*处理多余的元素

a, b, *rest = range(6)
print(a, b, rest)



C:\python35\python.exe E:/pytest/pytest8.5.py
0 1 [2, 3, 4, 5]

Process finished with exit code 0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值