为了不使用这么多行来声明这样的变量:
open = []
high = []
low = []
close = []
我可以这样做:
open,high,low,close = []
实际上有效
答案 0 :(得分:1)
没有。你问题中的例子不起作用。它会引发ValueError
。这是因为Python试图将四个值解压缩到open
,high
,low
和closed
,但是如果找不到任何值(这会在Python中引发错误) 2.x和Python 3.x):
>>> open, high, low, close = []
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: not enough values to unpack (expected 4, got 0)
>>>
要初始化同一行上的所有列表变量,您需要提供所有四个变量的列表:
>>> open, high, low, closed = [], [], [], []
>>>
>>> open
[]
>>> high
[]
>>> low
[]
>>> closed
[]
>>>