[None] *在python中是什么意思>>

问题描述 投票:0回答:3

我最近正在研究某人的代码和下面提供的部分代码

class Node:
def __init__(self, height=0, elem=None):
    self.elem = elem
    self.next = [None] * height

以上代码中的[None] * height是什么意思

我知道*运算符(如乘法和拆包)和None在python中的含义是什么,但这有所不同。

我最近正在研究某人的代码以及在类Node下面给出的一部分代码:def __init __(self,height = 0,elem = None):self.elem = elem self.next = [无] * height是什么意思...

python python-3.x nonetype iterable-unpacking
3个回答
0
投票
>>> [None]  * 5
[None, None, None, None, None]

0
投票

这表示None的列表,其中包含height个元素。例如,对于height = 3,它是此列表:


0
投票

如果您这样做-

© www.soinside.com 2019 - 2024. All rights reserved.