相关疑难解决方法(0)

python头部和尾部在一条线上

有没有pythonic方法解压缩第一个元素中的列表和单个命令中的"尾部"?

例如:

>> head, tail = **some_magic applied to** [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
>> head
1
>>> tail
[1, 2, 3, 5, 8, 13, 21, 34, 55]
Run Code Online (Sandbox Code Playgroud)

python list tail head

81
推荐指数
3
解决办法
8万
查看次数

在Python中创建一个列表 - 偷偷摸摸的东西?

抱歉,如果这没有任何意义,我对Python很新!

从解释器中的测试中,我可以看到list()并且[]两者都产生一个空列表:

>>> list()
[]
>>> []
[]
Run Code Online (Sandbox Code Playgroud)

从我到目前为止所学到的,创建对象的唯一方法是调用它的构造函数(__init__),但是当我输入时我没有看到这种情况发生[].那么通过执行[],Python然后映射到一个调用list()

python constructor list

10
推荐指数
4
解决办法
4051
查看次数

标签 统计

list ×2

python ×2

constructor ×1

head ×1

tail ×1